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 ...
随机推荐
- Java开发之多线程下载和断点续传
代码实现了多线程下载和断点续传功能 import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream ...
- 关于广义后缀树(多串SAM)的总结
之前我们给的SAM的例题,基本上是一个串建SAM的就能做的 如果要建多个串的SAM应该怎么做呢 首先看题,bzoj2780 我一开始的想法是SA以前的弄法,把串拼起来,中间加分隔符做SAM 这题确实可 ...
- windows8安装xna4.0不能开发Xbox和PC端游戏的解决办法
vs2012安装wp8后,只能开发手机端的xna游戏程序,没有xbox和pc端的,看来官方是不打算更新了,不过我们还是有办法的. 前提条件下,您得安装了vs2010和xna4.0 game studi ...
- 在SQL Server实现最短路径的搜索
开始 这是去年的问题了,今天在整理邮件的时候才发现这个问题,感觉顶有意思的,特记录下来. 在表RelationGraph中,有三个字段(ID,Node,RelatedNode),其中Node和Rela ...
- mysql 触发器学习(可以将mysql数据同步到redis)
1. 一个简单的例子 1.1. 创建表: create table t(s1 integer); 1.2. 触发器: delimiter | create trigger t_trigger befo ...
- auto make System.map to C header file
#!/bin/bash # auto make System.map to C header file # 说明: # 该脚本主要是将Linux内核生成的System.map文件中的符号.地址存入结构 ...
- 【原创】 Shuffling
在机器学习领域中,经常会听到“shuffling"这个术语.那么,shuffling到底是什么意思呢. 通常,shuffling指的是在SGD怎样依赖训练数据输入顺序的算法中,将训练数据随机 ...
- Windows安装weblogic
WebLogic安装结束 以下是进入MyEclipse启动配置WebLogic
- 如何使用spring中的Log4jConfigListener--删除
使用spring中的Log4jConfigListener有如如下好处: 1. 动态的改变记录级别和策略,不需要重启Web应用,如<Effective Enterprise Java> ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...