Clarke and puzzle

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

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
 
    对于操作1而言就是一个裸的nim博弈,答案就是 {c[x1][y1]^......^c[x2][y2]}
   操作二就是改变了格子中的一个数。
        用二维BIT来维护矩阵内的异或和即可。
 
  (最近总把下标写错,,把x1,y1写成了i,j检查半天, (误

 #include<bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
#define LL long long
int c[][];
int C[][];
int N,M;
inline int lowbit(int x){return x&-x;}
void change(int x,int y,int d){
for(int i=x;i<=N;i+=lowbit(i))
for(int j=y;j<=M;j+=lowbit(j))
C[i][j]^=d;
}
int ask(int x,int y){
int r=;
for(int i=x;i;i-=lowbit(i))
for(int j=y;j;j-=lowbit(j))
r^=C[i][j];
return r;
}
int main(){
int t,n,m,i,q,j,k,x1,x2,y1,y2;
scanf("%d",&t);
while(t--){
memset(C,,sizeof(C));
scanf("%d%d%d",&n,&m,&q);
N=n,M=m;
for(i=;i<=n;++i){
for(j=;j<=m;++j){
scanf("%d",&c[i][j]);
change(i,j,c[i][j]);
}
} int opt,d;
while(q--){
scanf("%d",&opt);
if(opt==){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int ans=(ask(x2,y2)^ask(x1-,y1-)^ask(x1-,y2)^ask(x2,y1-));
ans?puts("Yes"):puts("No");
}
else{
scanf("%d%d%d",&x1,&y1,&d);
change(x1,y1,(d^c[x1][y1]));
c[x1][y1]=d;
}
}
}
return ;
}

hdu-5465-二维BIT+nim的更多相关文章

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

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

  2. HDU 2159 二维费用背包问题

    一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...

  3. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

  4. F - F HDU - 1173(二维化一维-思维)

    F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...

  5. HDU 3496 (二维费用的01背包) Watch The Movie

    多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...

  6. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  7. hdu 2888 二维RMQ模板题

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. Coconuts HDU - 5925 二维离散化 自闭了

    TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...

  9. HDU 1263 二维map

    题意:给出一份水果的交易表,根据地区统计出水果的交易情况.   思路:二维map使用.   #include<cstdio> #include<string> #include ...

  10. hdu 2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. javascript闭包(Module模式)的用途和高级使用方式

    javascript闭包(Module模式)的用途和高级使用方式 javascript闭包的用途:1. 匿名自执行函数:或者可以理解为,避免污染全局变量2. 缓存:源于闭包的核心特性便是保存状态,应用 ...

  2. JMeter:全面的乱码解决方案

    中文乱码一直都是比较让人棘手的问题,我们在使用Jmeter的过程中,也会遇到中文乱码问题 接口:http://127.0.0.1:8090/test 这个接口有一个参数name,返回结果就是你传的na ...

  3. Python Web学习笔记之TCP/IP协议原理与介绍

    HTTP.FTP.SMTP.Telnet等等协议,哦!那个HTTP协议啊就是访问网页用的那个协议啊然后那个······其实······你懂得,我们应该从实际来了解他,理解网络协议的作用与功能,然后再从 ...

  4. margin显示怪异,外边距合并问题

    很多时候我们使用两个div,内层的div设置文字,需要垂直居中与上层div,但是怎么设置样式都不行,vertical-align:middle也不行. 代码: <div style=" ...

  5. 使用CloudFlare 的 PKI 工具集 cfssl 来生成 Certificate Authority (CA) 证书和秘钥文件

    要安装kubernetes最新版集群,https://github.com/opsnull/follow-me-install-kubernetes-cluster 这个文档必须要研习一下了. 以下实 ...

  6. 解决Navicat Premium 12 连接oracle数据库出现ORA-28547的问题

    1. 出现的问题... 下午工作时想连接Oracle数据库,使用的是Navicat Premium 12 . 数据库地址.用户名.密码.端口号都没有问题,但出现了ORA-28547:connectio ...

  7. bzoj 1010 玩具装箱toy -斜率优化

    P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具,第i件玩具 ...

  8. CRT中的时间(time_t和tm)(转载)

    转载:http://blog.csdn.net/bokee/article/details/5330682 首先介绍基本的时间概念. 时间一般分为两种,一种是本地时间(Local Time),一种是协 ...

  9. 网络安全、Web安全、渗透测试之笔经面经总结(二)

    这篇文章涉及的知识点有如下几方面: 1.SSL Strip(SSp)攻击到底是什么? 2.中间人攻击——ARP欺骗的原理.实战及防御 3会话劫持原理 4.CC攻击 5.添加时间戳防止重放攻击 6.浅析 ...

  10. QT学习资源

    http://www.qter.org/portal.php?mod=view&aid=26