Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维树状数组 随机化
来源:互联网 发布:淘宝店铺上新模板 编辑:程序博客网 时间:2024/06/05 08:12
Adieu l'ami.
Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence.
The space is represented by a rectangular grid of n × m cells, arranged into n rows and m columns. The c-th cell in the r-th row is denoted by (r, c).
Oshino places and removes barriers around rectangular areas of cells. Specifically, an action denoted by "1 r1 c1 r2 c2" means Oshino's placing barriers around a rectangle with two corners being (r1, c1) and (r2, c2) and sides parallel to squares sides. Similarly, "2 r1 c1 r2 c2" means Oshino's removing barriers around the rectangle. Oshino ensures that no barriers staying on the ground share any common points, nor do they intersect with boundaries of the n × m area.
Sometimes Koyomi tries to walk from one cell to another carefully without striding over barriers, in order to avoid damaging various items on the ground. "3 r1 c1 r2 c2" means that Koyomi tries to walk from (r1, c1) to (r2, c2) without crossing barriers.
And you're here to tell Koyomi the feasibility of each of his attempts.
The first line of input contains three space-separated integers n, m and q (1 ≤ n, m ≤ 2 500, 1 ≤ q ≤ 100 000) — the number of rows and columns in the grid, and the total number of Oshino and Koyomi's actions, respectively.
The following q lines each describes an action, containing five space-separated integers t, r1, c1, r2, c2 (1 ≤ t ≤ 3, 1 ≤ r1, r2 ≤ n, 1 ≤ c1, c2 ≤ m) — the type and two coordinates of an action. Additionally, the following holds depending on the value of t:
- If t = 1: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1;
- If t = 2: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1, the specified group of barriers exist on the ground before the removal.
- If t = 3: no extra restrictions.
For each of Koyomi's attempts (actions with t = 3), output one line — containing "Yes" (without quotes) if it's feasible, and "No" (without quotes) otherwise.
5 6 51 2 2 4 51 3 3 3 33 4 4 1 12 2 2 4 53 1 1 4 4
NoYes
2500 2500 81 549 1279 1263 21891 303 795 1888 24321 2227 622 2418 11613 771 2492 1335 14331 2017 2100 2408 21603 48 60 798 7291 347 708 1868 7923 1940 2080 377 1546
NoYesNo
For the first example, the situations of Koyomi's actions are illustrated below.
考试时问了nerther_nor题解,然后树状数组写错了。。
最后贴了份代码,然后光荣skip,要不就基本上紫了.mmp
好了说题解:
每次操作把矩形异或一个随机值,然后每次查询两个点的权值一不一样就行了
具体还是很简单的
就是矩形(x,y),(a,b) 在(x,y)(a+1,b+1),(x,b+1),(a+1,y)打标记
查询二维前缀异或和就行了
然后写树状数组手懒,query粘的modify,然后减号还是加号。泪
#include<cmath>#include<ctime>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<set>#include<map>using namespace std;typedef long long ll;inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(ll x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=2510;int n,m;ll bit[N][N],v[N][N];inline void modify(int x,int y,ll val){for(;x<=n;x+=(x&-x))for(int i=y;i<=m;i+=(i&-i))bit[x][i]^=val;}inline ll query(int x,int y){ll res=0;for(;x;x-=(x&-x))for(int i=y;i;i-=(i&-i))res^=bit[x][i];return res;}int main(){n=read(),m=read();int Q=read();register int x,y,a,b,opt;while(Q--){opt=read();x=read();y=read();a=read();b=read();if(opt==1){if(x>a)swap(a,x);if(y>b)swap(b,y);ll now=ll(rand())<<48ll|ll(rand())<<34ll|(rand())<<15ll|rand();v[x][y]=now;modify(x,y,now);modify(x,b+1,now);modify(a+1,b+1,now);modify(a+1,y,now);}else if(opt==2){if(x>a)swap(a,x);if(y>b)swap(b,y);ll now=v[x][y];modify(x,y,now);modify(x,b+1,now);modify(a+1,b+1,now);modify(a+1,y,now);}else {query(x,y)^query(a,b)?puts("No"):puts("Yes");}}return 0;}/*5 6 51 2 2 4 51 3 3 3 33 4 4 1 12 2 2 4 53 1 1 4 4*/
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维树状数组 随机化
- Codeforces Round #439 E. The Untended Antiquity (树状数组+随机化)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组
- Codeforces Round #439 (Div. 2) E:The Untended Antiquity(Hash+二维树状数组)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity hash+二维树状数组或二维线段树
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity(二维BIT)
- Codeforces 869 E. The Untended Antiquity 二维树状数组
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity (hash+数状数组)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity(Hash)
- codeforces 869E The Untended Antiquity 二维BIT + hash
- codeforces869EThe Untended Antiquity(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- Codeforces Round #368 (Div. 2) E. Garlands(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- CF #439 E The Untended Antiquity
- CF869 E. The Untended Antiquity
- 2017.10.9 DZY Loves Math VI 失败总结
- 【BZOJ3714】【PA2014】Kuglarz
- css各种动画
- HTML donhhua
- String类的私有属性value 怎么初始化的
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维树状数组 随机化
- 图解MotionEvent中getRawX、getRawY与getX、getY以及View中的getScrollX、getScrollY
- html5_动画练习
- css动画
- js鼠标移动让字体旋转360度
- 鼠标移动让图片倾斜45度
- httpclict和httpurl获取文字和图片
- 自定义控件_View
- String的默认初始值为什么