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}c​i,j​​。
aa想开挂,想知道如何打败bb。
他们要玩qq次游戏,每一次做一次操作:
1. 取出当中的一个子矩阵(x_1, y_1)-(x_2, y_2)(x​1​​,y​1​​)−(x​2​​,y​2​​)玩游戏。两个人轮流行动,每一次只能从这个子矩阵中的一个方格c_{i, j}c​i,j​​中减掉一个的数d(1 \le d \le c_{i, j})d(1≤d≤c​i,j​​),当一个格子的数为00时则不能减。如果操作完后另一者无法操作,那么胜利。否则失败。现在aa作为先手,想知道是否存在一种方案使得自己胜利。
2. 将c_{i, j}c​i,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∗10​5​​)。
接下来是一个nn行mm列的矩阵,其中第ii行第jj列的数为c_{i, j}(0 \le c_{i, j} \le 10^9)c​i,j​​(0≤c​i,j​​≤10​9​​)。
接下来时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)x​1​​,y​1​​,x​2​​,y​2​​(1≤x​1​​≤x​2​​≤n,1≤y​1​​≤y​2​​≤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≤10​9​​),表示将c_{x, y}c​x,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上是很容易的。

代码:

#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 二维线段树的更多相关文章

  1. HDU 1823 Luck and Love 二维线段树(树套树)

    点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. hdu 1823 Luck and Love 二维线段树

    题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...

  3. HDU 4819 Mosaic(13年长春现场 二维线段树)

    HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...

  4. hdu 4819 二维线段树模板

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

  5. HDU 1823 Luck and Love(二维线段树)

    之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...

  6. HDU 4819 Mosaic (二维线段树)

    Mosaic Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total S ...

  7. HDU 4819 Mosaic --二维线段树(树套树)

    题意: 给一个矩阵,每次查询一个子矩阵内的最大最小值,然后更新子矩阵中心点为(Max+Min)/2. 解法: 由于是矩阵,且要求区间最大最小和更新单点,很容易想到二维的线段树,可是因为之前没写过二维的 ...

  8. HDU 4819 Mosaic 二维线段树

    Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 4819 Mosaic (二维线段树&区间最值)题解

    思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...

随机推荐

  1. Eclipse搭建Struts框架,及一个简单的Struts例子

    一.下载struts2.0.1 http://struts.apache.org/downloads.html,下载struts-2.0.1-all.zip,这个压缩包中包含了开发struts2所需的 ...

  2. 基于邻接矩阵的深度优先搜索(DFS)

    题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2107&cid=1186 #include<stdio.h> #incl ...

  3. poj3666

    一道不错的dp题 就是最小修改代价,使序列变为一个非下降序或非上升(由于数据较弱直接求非下降即可,当然非上升非下降本质是一样的) 观察可得到,修改后得到的数列中的元素最后一定都在原序列中: 由此我们可 ...

  4. String中intern的方法

    首先查看官方API那个的解释: ——————————————————————————————————————— intern public String intern() 返回字符串对象的规范化表示形 ...

  5. javascript两行代码按指定格式输出日期时间

    javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...

  6. 【转】 实现 Cocos2d-x 全局定时器

    转自:http://www.tairan.com/archives/3998 cocos2d-x 中有自己的定时器实现,一般用法是在场景,层等内部实现,定时器的生命周期随着它们的消亡而消亡,就运行周期 ...

  7. HttpServerUtility类

    HttpServerUtility是一个工具类,为了在后台处理请求方便获取到一些常用的类型,Asp.net将很多常用的东西封装到这里. 比如可以使用其进行URL编码解码, HTML编码解码等. // ...

  8. Beginning Android 4 Programming Book学习

    Chapter 3 EditText不自动获取焦点,自动获取焦点但不显示软键盘  Page 122-123 只有定义了android:id属性的控件在屏幕翻转后状态才会被持久化  Page 133 C ...

  9. Android Fragment学习(一)

    说明 Fragment是在Android3.0(即API 11)才出现的,如果在之前的版本要使用,需要添加support库. Fragment可以认为是Actvity模块化的组件,可以很方便地被添加, ...

  10. 导出Excel帮助类

    using System; using System.Collections.Generic; using System.Text; using System.Data; using System.D ...