Codeforces869E The Untended Antiquity
来源:互联网 发布:linux qt usb 编辑:程序博客网 时间:2024/06/01 08:11
标签:模拟,标记法
Koyomi is helping Oshino, an acquaintanceof his, to take care of an open space around the abandoned Eikou Cram Schoolbuilding, Oshino's makeshift residence.
The space is represented by a rectangulargrid ofn × m cells, arranged into n rows and m columns. Thec-thcell in the r-th row is denoted by (r, c).
Oshino places and removes barriers aroundrectangular areas of cells. Specifically, an action denoted by "1r1c1 r2 c2" meansOshino's placing barriers around a rectangle with two corners being (r1, c1)and (r2, c2) and sides parallel to squaressides. Similarly, "2 r1 c1r2c2" means Oshino's removing barriers around therectangle. Oshino ensures that no barriers staying on the ground share anycommon points, nor do they intersect with boundaries of then × m area.
Sometimes Koyomi tries to walk from onecell to another carefully without striding over barriers, in order to avoiddamaging various items on the ground. "3r1 c1r2 c2" means that Koyomi tries to walkfrom (r1, c1) to (r2, c2)without crossing barriers.
And you're here to tell Koyomi thefeasibility of each of his attempts.
Input
The first line of input contains threespace-separated integersn, m and q (1 ≤ n, m ≤ 2 500, 1 ≤ q ≤ 100 000) — the number of rows and columns inthe grid, and the total number of Oshino and Koyomi's actions, respectively.
The following q lines each describesan action, containing five space-separated integerst, r1,c1, r2,c2 (1 ≤ t ≤ 3, 1 ≤ r1, r2 ≤ n, 1 ≤ c1, c2 ≤ m) — the type and two coordinates of an action. Additionally, thefollowing 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.
Output
For each of Koyomi's attempts (actions witht = 3), output one line — containing "Yes"(without quotes) if it's feasible, and "No" (without quotes)otherwise.
Examples
Input
5 6 5
1 2 2 4 5
1 3 3 3 3
3 4 4 1 1
2 2 2 4 5
3 1 1 4 4
Output
No
Yes
Input
2500 2500 8
1 549 1279 1263 2189
1 303 795 1888 2432
1 2227 622 2418 1161
3 771 2492 1335 1433
1 2017 2100 2408 2160
3 48 60 798 729
1 347 708 1868 792
3 1940 2080 377 1546
Output
No
Yes
No
Note
For the first example, the situations ofKoyomi's actions are illustrated below.
题意:给定一个大小为N*M的矩形和Q次操作,每次操作可以以(r1,c1)->(r2,c2)建立围墙,同样也可以拆除围墙,围墙将矩形划分为若干区域。若干次询问两个点的坐标是否在同一区域内。
分析:肯定是打标记操作了,将每一行单独视为一个序列,拆建围墙只需要将x=r1打上标记i,r2+1打上标记-1
在询问的时候,只需要判断该点所处的那一行,就可以知道其处于第几个区域中,如果区域相同,那么就输出yes
And else 这题的卡常很恶心啊,建议使用读入优化,数组不要开大了,否则绝对会TLE啊
Code
#include<bits/stdc++.h>#define rep(i,a,b) for(int i=a;i<=b;i++)#define dep(i,a,b) for(int i=a;i>=b;i--)using namespace std;const int maxn=2506;int was[maxn][maxn];inline int read(){int f=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}int main(){ int n=read(),m=read(),q=read(); rep(i,1,q){ int t=read(),r1=read(),c1=read(),r2=read(),c2=read();if(t==1)rep(r,r1,r2){was[r][c1]=i;was[r][c2+1]=-1;}else if(t==2)rep(r,r1,r2)was[r][c1]=was[r][c2+1]=0;else{ int st=0,res1=0,res2=0;dep(i,c1,0) if(was[r1][i]>0) if(st==0){res1=was[r1][i];break;} else st++;else if(was[r1][i]<0)st--;st=0;dep(i,c2,0) if(was[r2][i]>0) if(st==0){res2=was[r2][i];break;}else st++;else if(was[r2][i]<0)st--; printf("%s",res1==res2?"Yes\n":"No\n");}}return 0;}
- Codeforces869E The Untended Antiquity
- CF869 E. The Untended Antiquity
- CF869 E. The Untended Antiquity
- CF #439 E The Untended Antiquity
- Codeforces Round #439 E. The Untended Antiquity (树状数组+随机化)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
- Codeforces 869 E. The Untended Antiquity 二维树状数组
- codeforces 869E The Untended Antiquity 二维BIT + hash
- CF 869E(The Untended Antiquity-Hash值维护连通性)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity
- [哈希+差分] Codeforces 869E. The Untended Antiquity
- codeforces—— 869E —— 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(二维BIT)
- 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(Hash)
- 机器学习数学基础--牛顿法
- 542. 01 Matrix -- Medium
- tensorflow实战之二:MNIST手写数字识别的优化1-代价函数优化
- 92. Reverse Linked List II
- JavaScript高级
- Codeforces869E The Untended Antiquity
- 为什么我博客里的插图都不见了???!!!
- java学习第24天(续),学习几个API,indexOf(),charAt(),toUpperCase(),toLowerCase(),subString(),trim()
- nginx 反向代理
- 每天学些redis命令(3)
- Java:如何利用两个栈实现队列
- 利用QEMU运行ARM开发环境
- 7-38 支票面额(15 分)
- 数组