这个题要求对区间进行更新,然后找出某点的值,
思路:用树状数组的逆向思维做~网上有不少的题解,可以参考下~
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1010;
int T,n,m;
bool t[maxn][maxn];
int lowbit(int x)
{
return x&(-x);
}
void update(int row,int col)
{
for(int i=row;i>0;i-=lowbit(i))
for(int j=col;j>0;j-=lowbit(j))
t[i][j]^=1;
}
int sum(int row,int col)
{
int ans=0;
for(int i=row;i<=n;i+=lowbit(i))
for(int j=col;j<=n;ans^=t[i][j],j+=lowbit(j));
return ans;
}
int main()
{
scanf("%d",&T);
while(T--)
{
memset(t,0,sizeof(t));
scanf("%d%d",&n,&m);
while(m--)
{
char op[5];
scanf("%s",op);
if(op[0]=='C')
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
update(x2,y2);
update(x1-1,y1-1);
update(x2,y1-1);
update(x1-1,y2);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",sum(x,y)&1);
}
}
printf("\n");
}
return 0;
}