一个地图,然后三种操作
1.一个矩阵四周加上障碍 (不与任何障碍相交)
2.一个矩阵四周的障碍消除
3.问你两个点之间是否纯在一条路径不经过障碍
矩阵大小2500^2,操作10w
树状数组
考虑每次操作定一个hash值,然后每次在那个矩阵上xor那个hash值,问题转化为2点hash值是否相同。
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
#define
#define
typedef unsigned long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int n,m;
#define
ll f[MAXN][MAXN]={0};
void add(int x,int y,ll v) {
for(int i=x;i<=n;i+=i&(-i))
for(int j=y;j<=m;j+=j&(-j))
f[i][j]^=v;
}
ll qur(int x,int y) {
ll v=0;
for(int i=x;i;i-=i&(-i))
for(int j=y;j;j-=j&(-j))
v^=f[i][j];
return v;
}
map < pair<pi, pi > ,ll > h;
ll rand(int r1,int c1,int r2,int c2) {
if (h.find(mp(mp(r1,c1),mp(r2,c2)))!=h.end())
return h[mp(mp(r1,c1),mp(r2,c2))];
ll rn=rand();
rn= (rn<<16ULL)| rand();
srand(rn);
h[mp(mp(r1,c1),mp(r2,c2)) ]=rn;
return rn;
}
int q;
int main()
{
// freopen("E.in","r",stdin);
// freopen(".out","w",stdout);
srand(123);
n=read(),m=read(),q=read();
n+=3,m+=3;
For(i,q) {
int t=read(),r1=read(),c1=read(),r2=read(),c2=read();
ll p=rand(r1,c1,r2,c2);
if (t<=2) {
add(r2+1,c2+1,p);
add(r2+1,c1,p);
add(r1,c2+1,p);
add(r1,c1,p);
}
else {
ll ans1=qur(r2,c2);
ll ans2=qur(r1,c1);
if (ans1==ans2) {
puts("Yes");
}else puts("No");
}
}
return 0;
}