Clarke and puzzle

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 673    Accepted Submission(s): 223

Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke split into two personality a and b, they are playing a game. 
There is a n∗m matrix, each grid of this matrix has a number ci,j. 
a wants to beat b every time, so a ask you for a help. 
There are q operations, each of them is belonging to one of the following two types: 
1. They play the game on a (x1,y1)−(x2,y2) sub matrix. They take turns operating. On any turn, the player can choose a grid which has a positive integer from the sub matrix and decrease it by a positive integer which less than or equal this grid's number. The player who can't operate is loser. a always operate first, he wants to know if he can win this game. 
2. Change ci,j to b.

 
Input
The first line contains a integer T(1≤T≤5), the number of test cases. 
For each test case: 
The first line contains three integers n,m,q(1≤n,m≤500,1≤q≤2∗105) 
Then n∗m matrix follow, the i row j column is a integer ci,j(0≤ci,j≤109) 
Then q lines follow, the first number is opt. 
if opt=1, then 4 integers x1,y1,x1,y2(1≤x1≤x2≤n,1≤y1≤y2≤m) follow, represent operation 1. 
if opt=2, then 3 integers i,j,b follow, represent operation 2.
 
Output
For each testcase, for each operation 1, print Yes if a can win this game, otherwise print No.
 
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:
The first enquiry: $a$ can decrease grid $(1, 2)$'s number by $1$. No matter what $b$ operate next, there is always one grid with number $1$ remaining . So, $a$ wins.
The second enquiry: No matter what $a$ operate, there is always one grid with number $1$ remaining. So, $b$ wins.
 
Source
 
 
题目大意:给你t组测试数据。每组测试数据中有一组n,m,q,分别表示有一个n*m的矩阵,有q组询问。每组询问中,操作1表示查询(x1,y1) ---(x2,y2)在矩阵中做Nim游戏先手是否会赢。操作2表示要把矩阵中某个值修改为c。
 
 
知识补充:对于一维树状数组见的比较多。二维还是见的少(弱)。那么二维跟一维的区别是:一般意义上二维用来求的是矩阵的和。对于C[x][y],这里的定义就是从(1,1)---(x,y)矩阵的元素和。我们可以将每行抽象成一个点,这样其实就是抽象成了求一维的情况。其实一维跟二维实现的写法差别很容易想到。对于二维BIT,我们得到C数组,需要n^2log(n)^2的时间复杂度。
  
求和:

int sum(int x,int y){
int ret=0;
for(int i=x;i>0;i-=lowbit(i)){
for(int j=y;j>0;j-=lowbit(j)){
ret+=C[i][j];
}
}
return ret;
}

修改:

void modify(int x,int y,int val){
for(int i=x;i<=n;i+=lowbit(i)){
for(int j=y;j<=m;j+=lowbit(j)){
C[i][j] += val;
}
}
}

  

 
 
解题思路:
 
 
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
const int maxn=550;
int a[maxn][maxn];
int C[maxn][maxn];
int n,m;
int lowbit(int x){
return x & (-x);
}
void modify(int x,int y,int val){
for(int i=x;i<=n;i+=lowbit(i)){
for(int j=y;j<=m;j+=lowbit(j)){
C[i][j] ^= val;
}
}
}
int sum(int x,int y){
int ret=0;
for(int i=x;i>0;i-=lowbit(i)){
for(int j=y;j>0;j-=lowbit(j)){
ret ^=C[i][j];
}
}
return ret;
}
int main(){
int t,q;
scanf("%d",&t);
while(t--){
memset(a,0,sizeof(a));
memset(C,0,sizeof(C));
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
modify(i,j,a[i][j]);
}
}
int typ,x1,x2,y1,y2,c;
for(int i=0;i<q;i++){
scanf("%d",&typ);
if(typ==1){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int ans1,ans2,ans3,ans4;
ans1=sum(x2,y2);
ans2=sum(x2,y1-1);
ans3=sum(x1-1,y2);
ans4=sum(x1-1,y1-1);
int ans=ans1^ans2^ans3^ans4;
printf("%s\n",ans==0?"No":"Yes");
}else{
scanf("%d%d%d",&x1,&y1,&c);
modify(x1,y1,c^a[x1][y1]);
a[x1][y1]=c;
}
}
}
return 0;
}

  

 
 

HDU 5465——Clarke and puzzle——————【树状数组BIT维护前缀和+Nim博弈】的更多相关文章

  1. HH的项链 树状数组动态维护前缀

    #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const ...

  2. HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle  Accepts: 42  Submissions: 26 ...

  3. hdu 5592 ZYB's Game 树状数组

    ZYB's Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=55 ...

  4. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  5. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. 「BZOJ1537」Aut – The Bus(变形Dp+线段树/树状数组 最优值维护)

    网格图给予我的第一反应就是一个状态 f[i][j] 表示走到第 (i,j) 这个位置的最大价值. 由于只能往下或往右走转移就变得显然了: f[i][j]=max{f[i-1][j], f[i][j-1 ...

  7. HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                         ...

  8. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

  9. HDU 1394 Minimum Inversion Number (树状数组求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多 ...

随机推荐

  1. Rails多个复选框--check_box_tag

    一.简单粗暴的解决方法 view <% @roles.each do |role| %> <%= check_box_tag 'roles[]', role.id%> < ...

  2. 关于Windows文件读写_暗涌_新浪博客

    关于Windows文件读写_暗涌_新浪博客     这几天在研究怎么才能加快windows文件读写速度,搜了很多文章,MSDN也看了不少.稍微给大家分享一下.     限制windows文件读写速度的 ...

  3. R: which(查询位置)、%in% (是否存在)、ifelse(判断是否):

    ################################################### 问题:ifelse.which.%in%    18.4.27 解决方案: > x < ...

  4. 6、R语言绘制带errorbar 的柱状图

    转载:http://www.cnblogs.com/xudongliang/p/7283733.html data <- data.frame(mean = c(10, 15), sd = c( ...

  5. 阶段3-团队合作\项目-网络安全传输系统\sprint1-传输子系统设计\第3课-加密传输优化

    对之前的传输系统进行加密,使之成为加密的网络传输系统 客户端编程模型 通过以上模型对传统的TCP传输模型进行优化 首先完成初始化工作,它是要在创建socket之前完成 主要是以上四个函数的实现,那么这 ...

  6. .Net开发中的@ 和 using 使用技巧

    一.@符号的妙用 1.可以作为保留关键字的标识符 C#规范当中,不允许使用保留关键字(class.bool等)当作普通的标识符来命名,这时候@符号作用就体现 出来了,可以通过@符号前缀把这些保留关键字 ...

  7. 用ORBSLAM2运行TUM Dataset数据集Monocular Examples

    参照https://github.com/raulmur/ORB_SLAM2/blob/master/README.md 运行 4. Monocular Examples TUM Dataset 数据 ...

  8. Equals 和 == 的区别--转

    在比较Equals 和 ==的区别前.我们先来了解下相关的知识 C#数据类型 1.值类型 值类型有: 值类型包括:简单类型.结构类型.枚举类型. byte(1).sbyte(1).short(2).u ...

  9. ASP.NET MVC中的 _ViewStart.cshtml文件的作用【摘抄】

    ViewStart 在前面的例子中,每一个视图都是使用Layout 属性来指定它的布局.如果多个视图使用同一个布局,就会产生冗余,并且很难维护. _ViewStart.cshtml 页面可用来消除这种 ...

  10. neutron负载均衡高可用测试

    对工作中,实验环境的一个小总结 1.创建高可用负载均衡器------创建高可用的时候,添加上ha-mode参数即可 neutron lb-pool-create --lb-method ROUND_R ...