E. The Untended Antiquity
Problem Statement
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.
Input
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.
Output
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.
Examples
Example 1
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
Example 2
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 2100 2408 2160
3 48 60 798 729
1 347 708 1868 792
1940 2080 377 1546
Output
No
Yes
No
Note
For the first example, the situations of Koyomi’s actions are illustrated below.
题意
给你一个n*m大小的平面直角坐标系,再给你q个操作,每个操作有五个参数t,x,y,xx,yy,其中t是操作类型,t=1表示在平面直角坐标系上添加了一个左上角为(x,y),右下角为(xx,yy)的矩形,t=2则表示删除(保证在删除前已经添加了);而t=3则是询问,一个人从起点(x,y)走到终点(xx,yy)能否走到,走的时候不能穿过任何一个矩形。
思路
这题……有人用O(q^2)水过去了233..我的做法是随机+二维树状数组。对于每一个添加的矩形,我们给他随机rand一个值,并在二维树状数组里加上这个值,用一个map
Code
#include<bits/stdc++.h>using namespace std;typedef long long ll;inline void readInt(int &x) {x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;}inline void readLong(ll &x) {x=0;ll f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;}/*================Header Template==============*/#define lb(x) x&(-x)#define mk make_pairtypedef pair<int,int> pii;ll n,m,q,tree[3010][3010],type,x,y,xx,yy;map<pii,ll> mp;inline void add(ll x,ll y,ll Add) {for(ll i=x;i<=n;i+=lb(i))for(ll j=y;j<=m;j+=lb(j))tree[i][j]+=Add;}inline ll ssum(ll x,ll y) {ll ans=0;for(ll i=x;i>0;i-=lb(i)) for(ll j=y;j>0;j-=lb(j)) ans+=tree[i][j];return ans;}inline ll randll() {ll x=rand();x=(x<<12)|rand();x=(x<<12)|rand();x=(x<<12)|rand();return x;}int main() {srand(time(0));readLong(n);readLong(m);readLong(q);for(ll i=1;i<=q;i++){readLong(type);readLong(x);readLong(y);readLong(xx);readLong(yy);if(type==1) {xx++;yy++;ll tmp=randll();pii now=mk(x*n+y,xx*n+yy);mp[now]=tmp;add(x,y,tmp);add(x,yy,-tmp);add(xx,y,-tmp);add(xx,yy,tmp);}else if(type==2) {xx++;yy++;pii now=mk(x*n+y,xx*n+yy);ll k=mp[now];add(x,y,-k);add(x,yy,k);add(xx,y,k);add(xx,yy,-k);}else if(type==3) {ll tmpx=ssum(x,y),tmpy=ssum(xx,yy);if(tmpx==tmpy)puts("Yes");elseputs("No");}}return 0;}