思路:典型的二维异或树状数组,有一个结论是在x位置放置了一个元素,只会对x+2,x+4等位置产生影响
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 1005;
LL lowbit(LL x){return x&(-x);}
LL c[2][2][maxn][maxn];
int n,m;
void update(int x1,int y1,LL v)
{
for(int i = x1;i<=maxn;i+=lowbit(i))
for(int j = y1;j<=maxn;j+=lowbit(j))
c[x1&1][y1&1][i][j]^=v;
}
LL query(int x1,int y1)
{
LL ans = 0;
for(int i=x1;i;i-=lowbit(i))
for(int j = y1;j;j-=lowbit(j))
ans^=c[x1&1][y1&1][i][j];
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i = 1;i<=m;i++)
{
int op,x1,y1,x2,y2;
scanf("%d%d%d%d%d",&op,&x1,&y1,&x2,&y2);
if(op==1)
{
LL ans = 0;
ans^=query(x1-1,y1-1);
ans^=query(x1-1,y2);
ans^=query(x2,y1-1);
ans^=query(x2,y2);
printf("%lld\n",ans);
}
else
{
LL v;
scanf("%lld",&v);
update(x1,y1,v);
update(x1,y2+1,v);
update(x2+1,y1,v);
update(x2+1,y2+1,v);
}
}
}