其实很简单的题,然而之前题意读错了……
我们怎么判断是否存在一个矩形,覆盖了一个点而没覆盖另一个点呢?实际上只要做个矩形覆盖就行了,若两个点上覆盖的矩形集合不同,则说明两点不可达。
我们可以对每个矩形,对应一个哈希值,进行矩形加。然后询问时判断两点的值是否相同即可。
矩形加,我们可以差分,然后二维树状数组实现。
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn=2515;
typedef unsigned LL;
typedef unsigned long long uLL;
int n,m,Q,_test;
uLL rdm[maxn];
LL bit[maxn][maxn];
void Updata(int _x,int _y,int val){
for(int x=_x;x<=n;x+=(x&(-x)))
for(int y=_y;y<=m;y+=(y&(-y))) bit[x][y]+=val;
}
LL Query(int _x,int _y){
LL res=0;
for(int x=_x;x;x-=(x&(-x)))
for(int y=_y;y;y-=(y&(-y))) res+=bit[x][y];
return res;
}
int main(){
freopen("E.in","r",stdin);
freopen("E.out","w",stdout);
srand(2333); for(int i=1;i<=2505;i++) rdm[i]=(rand()<<15)+rand(), rdm[i]+=(rdm[i]<<30)+(rand()<<15)+rand();
scanf("%d%d%d",&n,&m,&Q); n++; m++;
while(Q--){
int _type,x,y,_x,_y; scanf("%d%d%d%d%d",&_type,&x,&y,&_x,&_y);
int hsh=(rdm[x]*13+rdm[y]*53+rdm[_x]*17+rdm[_y]*15)%1000000007;
if(_type==1) Updata(x,y,hsh), Updata(x,_y+1,-hsh), Updata(_x+1,y,-hsh), Updata(_x+1,_y+1,hsh); else
if(_type==2) Updata(x,y,-hsh), Updata(x,_y+1,hsh), Updata(_x+1,y,hsh), Updata(_x+1,_y+1,-hsh); else
if(Query(x,y)==Query(_x,_y)) printf("Yes\n"); else printf("No\n");
}
}