做了一晚上,发现我因为定义变量n的时候没有注意到作用域,然后更新时完全不更新,苦恼了一晚上,debug也没找到错误,后来使劲的看呀看才找到- -
#include <cstdio>
#include <cstring>
using namespace std;
int s[1010][1010]={0};
int n;
int lowbit(int x)
{
return x&(-x);
}
void updata(int x,int y)
{
int i,k;
for(i=x; i<=n; i+=lowbit(i))
for(k=y; k<=n; k+=lowbit(k))
s[i][k]++;
}
int sum(int i,int j)
{
int res=0;
int x=i,y=j;
for(x=i;x>0;x-=lowbit(x))
for(y=j;y>0;y-=lowbit(y))
res+=s[x][y];
return res;
}
int main()
{
int x;
int t;
char c[2];
int x1,y1,x2,y2;
scanf("%d",&x);
while(x--)
{
memset(s,0,sizeof(s));
scanf("%d%d",&n,&t);
while(t--)
{
scanf("%s",c);
if(c[0]=='C')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++;y1++;x2++;y2++;
updata(x2,y2);
updata(x1-1,y1-1);
updata(x1-1,y2);
updata(x2,y1-1);
}
else
{
scanf("%d%d",&x1,&y1);
printf("%d\n",sum(x1,y1)%2);
}
}
printf("\n");
}
return 0;
}