Codeforces869e the untended antiquity

阅读全文大概需要 3分钟
本文总阅读量
Posted by yjjr's blog on February 6, 2018

标签:模拟,标记法

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;
}



本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr