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 ...
随机推荐
- Miles per gallon to kilometers per liter
Miles per gallon to kilometers per liter 1 Imperial Gallon = 4.54609188 litres 1 Mile = 1.609344 kil ...
- 中国海洋大学第四届朗讯杯高级组 A 2718 Rocky(模拟)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718 题意:优先直走,右 左 后.... ...
- Arch 常用工具
一.网络浏览 pacman -S firefox firefox-i18n注:该命令中的前者为 Firefox 主程序,后者为语言包.pacman -S opera 二.图像编辑 pacman -S ...
- [swustoj 917] K-lucky-number
K-lucky-number(0917) 问题描述 K-lucky-number is defined as add up the number of each bit is a multiple o ...
- CentOS6.5_Nginx1.40_Php5.57_MySQL5.5.35编译安装全记录
环境说明:CentOS 6.5 32位 PHP Version 5.5.7 mysql version _5.6.16 一.准备工作 配置防火墙,允许防火墙通过22(sshd).80(WEB).3 ...
- 【转】Cocos2d-x 弹出对话框的设计与实现
转自:http://www.tairan.com/archives/4854 我们时常需要这么些功能,弹出一个层,给与用户一些提示,这也是一种模态窗口,在没有对当前对话框进行确认的时候,不能继续往下操 ...
- SharePoint默认的欢迎WebPart中超链接样式
转:http://www.cnblogs.com/Bear-Study-Hard/archive/2010/03/22/1691641.html 在core.css文件中 .ms-SpLinkButt ...
- Cookie帮助类
using System; using System.Collections.Generic; using System.Text; using System.Web; namespace AIMSC ...
- java jvm学习笔记十(策略和保护域)
欢迎转载请说明出处:http://blog.csdn.net/yfqnihao/article/details/8271415 前面一节,我们做了一个简单的实验,来说明什么是策略文件,在文章的最后,也 ...
- HDU 5624 KK's Reconstruction 最小生成树
题意:这是bc round 71 div 1 的 1004 直接去看中文题意 分析: 首先,一种合法方案对应了原图的一棵生成树. 我们知道,最小生成树有一个性质是最大边最小. 因此,我们可以枚举生成树 ...