hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5465
Description
- 克拉克是一名人格分裂患者。某一天,有两个克拉克(aa和bb)在玩一个方格游戏。
- 这个方格是一个n*mn∗m的矩阵,每个格子里有一个数c_{i, j}ci,j。
- aa想开挂,想知道如何打败bb。
- 他们要玩qq次游戏,每一次做一次操作:
- 1. 取出当中的一个子矩阵(x_1, y_1)-(x_2, y_2)(x1,y1)−(x2,y2)玩游戏。两个人轮流行动,每一次只能从这个子矩阵中的一个方格c_{i, j}ci,j中减掉一个的数d(1 \le d \le c_{i, j})d(1≤d≤ci,j),当一个格子的数为00时则不能减。如果操作完后另一者无法操作,那么胜利。否则失败。现在aa作为先手,想知道是否存在一种方案使得自己胜利。
- 2. 将c_{i, j}ci,j的数改成bb
Input
- 第一行一个整数T(1 \le T \le 5)T(1≤T≤5),表示数据的组数。
- 每组数据第一行为三个整数n, m, q(1 \le n, m \le 500, 1 \le q \le 2*10^5)n,m,q(1≤n,m≤500,1≤q≤2∗105)。
- 接下来是一个nn行mm列的矩阵,其中第ii行第jj列的数为c_{i, j}(0 \le c_{i, j} \le 10^9)ci,j(0≤ci,j≤109)。
- 接下来时qq行,第一个数为optopt。当opt=1opt=1时,后面接着四个整数,依次表示x_1, y_1, x_2, y_2(1 \le x_1 \le x_2 \le n, 1 \le y_1 \le y_2 \le m)x1,y1,x2,y2(1≤x1≤x2≤n,1≤y1≤y2≤m),表示一个询问;当opt=2opt=2时,后面接着三个整数x, y, z(1 \le x \le n, 1 \le y \le m, 0 \le z \le 10^9)x,y,z(1≤x≤n,1≤y≤m,0≤z≤109),表示将c_{x, y}cx,y更改为zz。
Output
- 对于每组数据,每个询问输出aa是否能胜利,如果能,输出YesYes,否则输出NoNo。
Sample Input
- 1
- 1 2 3
- 1 2
- 1 1 1 1 2
- 2 1 2 1
- 1 1 1 1 2
Sample Output
- Yes
- No
HINT
题意
题解:
题目要求二维的nim游戏,考虑到nim的结论是xor和为0则必败、否则必胜,那么我们只需要维护子矩阵的xor和。由于xor有前缀和性质,所以我们可以用一个二维bit来维护(1, 1)-(a, b)的矩阵的xor和,然后由sum(x2, y2) \ xor \ sum(x2, y1-1) \ xor \ sum(x1-1, y2) \ xor \ sum(x1-1, y1-1)sum(x2,y2) xor sum(x2,y1−1) xor sum(x1−1,y2) xor sum(x1−1,y1−1)来得到答案即可。单点修改在bit上是很容易的。
@)1%KBO0HM418$J94$1R.jpg)
代码:
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- const int INF = 0x3f3f3f3f;
- const int MinN = ;
- struct Nodey
- {
- int l,r;
- int val;
- };
- int locy[MinN],locx[MinN] , n , m, q;
- struct Nodex
- {
- int l,r;
- Nodey sty[MinN*];
- void build(int i,int _l,int _r)
- {
- sty[i].l = _l;
- sty[i].r = _r;
- sty[i].val = ;
- if(_l == _r)
- {
- locy[_l] = i;
- return;
- }
- int mid = (_l + _r)/;
- build(i<<,_l,mid);
- build((i<<)|,mid+,_r);
- }
- int queryMin(int i,int _l,int _r)
- {
- if(sty[i].l == _l && sty[i].r == _r)
- return sty[i].val;
- int mid = (sty[i].l + sty[i].r)/;
- if(_r <= mid)return queryMin(i<<,_l,_r);
- else if(_l > mid)return queryMin((i<<)|,_l,_r);
- else return queryMin(i<<,_l,mid) ^ queryMin((i<<)|,mid+,_r);
- }
- }stx[MinN*];
- void build(int i,int l,int r)
- {
- stx[i].l = l;
- stx[i].r = r;
- stx[i].build(,,);
- if(l == r)
- {
- locx[l] = i;
- return;
- }
- int mid = (l+r)/;
- build(i<<,l,mid);
- build((i<<)|,mid+,r);
- }
- //修改值
- void Modify(int x,int y,int val)
- {
- int tx = locx[x];
- int ty = locy[y];
- stx[tx].sty[ty].val = val;
- for(int i = tx;i;i >>= )
- for(int j = ty;j;j >>= )
- {
- if(i == tx && j == ty)continue;
- if(j == ty)
- {
- stx[i].sty[j].val = stx[i<<].sty[j].val ^ stx[(i<<)|].sty[j].val;
- }
- else
- {
- stx[i].sty[j].val = stx[i].sty[j<<].val ^ stx[i].sty[(j<<)|].val;
- }
- }
- }
- int queryMin(int i,int x1,int x2,int y1,int y2)
- {
- if(stx[i].l == x1 && stx[i].r == x2)
- return stx[i].queryMin(,y1,y2);
- int mid = (stx[i].l + stx[i].r)/;
- // cout << stx[i].l << " " << stx[i].r << " " << mid << endl;
- if(x2 <= mid)return queryMin(i<<,x1,x2,y1,y2);
- else if(x1 > mid)return queryMin((i<<)|,x1,x2,y1,y2);
- else return queryMin(i<<,x1,mid,y1,y2) ^ queryMin((i<<)|,mid+,x2,y1,y2);
- }
- int main()
- {
- //freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- int T;
- scanf("%d",&T);int m;
- while(T--)
- {
- int q;
- scanf("%d%d",&n,&m);
- scanf("%d",&q);
- build(,,);
- for(int i = ;i <= n;i++)
- for(int j = ;j <= m;j++)
- {
- int a;
- scanf("%d",&a);
- Modify(i,j,a);
- }
- int x,y,L;
- while(q--)
- {
- int k;scanf("%d",&k);
- if(k==)
- {
- int x1,x2,y1,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
- int ans = queryMin(,x1,x2,y1,y2);
- if(ans == )printf("No\n");else printf("Yes\n");
- }
- else
- {
- int x1,y1,z;scanf("%d%d%d",&x1,&y1,&z);
- Modify(x1,y1,z);
- }
- }
- }
- return ;
- }
hdu 5465 Clarke and puzzle 二维线段树的更多相关文章
- HDU 1823 Luck and Love 二维线段树(树套树)
点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1823 Luck and Love 二维线段树
题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...
- HDU 4819 Mosaic(13年长春现场 二维线段树)
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...
- hdu 4819 二维线段树模板
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
- HDU 1823 Luck and Love(二维线段树)
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...
- HDU 4819 Mosaic (二维线段树)
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...
- HDU 4819 Mosaic --二维线段树(树套树)
题意: 给一个矩阵,每次查询一个子矩阵内的最大最小值,然后更新子矩阵中心点为(Max+Min)/2. 解法: 由于是矩阵,且要求区间最大最小和更新单点,很容易想到二维的线段树,可是因为之前没写过二维的 ...
- HDU 4819 Mosaic 二维线段树
Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 4819 Mosaic (二维线段树&区间最值)题解
思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...
随机推荐
- Android开发之一些资源索引
1.android标题栏(titlebar)显示进度条 protected void onCreate(Bundle savedInstanceState) { super.onCreate(save ...
- 5个难以置信的VS 2015预览版新特性
Visual Studio 2015 Preview包含了很多强大的新特性,无论你是从事WEB应用程序开发,还是桌面应用程序开发,甚至是移动应用开发,VS 2015都将大大提高你的开发效率.有几个特性 ...
- UVALive 3211 Now or later(2-SAT,二分,Kosaraju)
题意: 有n个飞机要降落,每机都可以在两个时间点上选择降落.但是两机的降落时间间隔太小会影响安全性,所以,要求两机的降落时间应该达到最大,当然也不能冲突了.问最大的时间间隔是多少?(其实问的是max( ...
- 装饰器模式(Decorator)
转自http://blog.csdn.net/hust_is_lcd/article/details/7884320 1.认识装饰器模式 装饰模式能够实现动态的为对象添加功能,是从一个对象外部来给对象 ...
- java中正则表达式
在<java编程思想>中,java中的 \\ 表示“我要插入一个正则表达式的反斜线,所以其后的字符具有特殊的意义.”如果想插入一个普通的反斜线,那么应该使用 \\\\. 理解: 我们使用的 ...
- css的框架——common.css
@charset "utf-8"; /* 字体 */ .n{ font-weight:normal; font-style:normal; } .b{font-weight:bol ...
- iOS--跳转到APPstore评分
本代码适用于iOS7之后的版本: NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/ ...
- sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page
转:http://blog.csdn.net/chenxinxian/article/details/8720893 在sharepoint 2010的页面中,我们发现,没有页尾,如果我们需要给页面添 ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.4.1
Let $x,y,z$ be linearly independent vectors in $\scrH$. Find a necessary and sufficient condition th ...
- Kettle定时执行(ETL工具)【转】
1,Kettle跨平台使用. 例如:在AIX下(AIX是IBM商用UNIX操作系统,此处在LINUX/UNIX同样适用),运行Kettle的相关步骤如下: 1)进入到Kettle部署的路径 ...