hdu-5465-二维BIT+nim
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
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.
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.
1 2 3
1 2
1 1 1 1 2
2 1 2 1
1 1 1 1 2
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.
#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的更多相关文章
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- HDU 2159 二维费用背包问题
一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...
- hdu 4819 二维线段树模板
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
- F - F HDU - 1173(二维化一维-思维)
F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...
- HDU 3496 (二维费用的01背包) Watch The Movie
多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- hdu 2888 二维RMQ模板题
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Coconuts HDU - 5925 二维离散化 自闭了
TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...
- HDU 1263 二维map
题意:给出一份水果的交易表,根据地区统计出水果的交易情况. 思路:二维map使用. #include<cstdio> #include<string> #include ...
- hdu 2888 二维RMQ
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- selenium自动化定位方法
用selenium操作浏览器进行自动化操作其实就是通过元素属性执行相关操作.所以,我们要知道怎样去查找元素,定位元素. 常见的定位属性有: #查找元素的id find_elements_by_id(i ...
- Linux中Postfix邮件原理介绍(一)
邮件相关协议 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议, 工作在TCP的25端口.它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式 ...
- keepalived+lvs高可用集群
LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国 ...
- Nginx 灰度实现方式(支持纯灰度,纯生产,50度灰及更多比例配置)
前言 Nginx相关技术短信本篇幅不做详细介绍,所以学习本文之前要对Nginx有相关的了解. 生产环境即线上环境,在经历开发.测试再到上线,不可避免的会更新生产环境,但谁又能保证测试过的代码到线上运行 ...
- laravel 对接支付宝
使用的库 omnipay-alipay 申请支付宝支付 这个就不说了, 不明白如何下手的伙伴让运营去和支付宝客服联系吧 composer 安装git库 将以下代码添加到 composer.json { ...
- apt-get build-dep
apt-get 里面有个 build-dep参数,手册写着:build-dep causes apt-get to install/remove packages in an attempt to s ...
- 在Windows下搭建Android开发环境及遇到的问题
转载1:http://www.cnblogs.com/xdp-gacl/p/4322165.html 转载2:http://www.cnblogs.com/zoupeiyang/p/4034517.h ...
- 【javascript】数据结构-链表
// 创建一个链表 function LinkedList(){ // 创建一个Node辅助类,表示需要加入列表的项,它包含一个element属性,即表示需要加入到列表中的值,next属性表示指向下一 ...
- mysql数据库分库分表(Sharding)
mysql数据库切分 前言 通过MySQLReplication功能所实现的扩展总是会受到数据库大小的限制.一旦数据库过于庞大,尤其是当写入过于频繁,非常难由一台主机支撑的时候,我们还是会面临到扩展瓶 ...
- [BZOJ2208][Jsoi2010]连通数 暴力枚举
Description Input 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i行第j列的1表示顶点i到j有边,0则表示无边. Output 输出一行一个整数,表示该图 ...