POJ 2155 Matrix

2014-11-24 07:52:33 · 作者: · 浏览: 0
[cpp]
#include
#include
const int maxn=1001;
int c[maxn][maxn];
inline int lowbit(int x)
{
return x&(-x);
}
int sum(int x,int y)
{
int ans=0;
for(int i=x; i>0; i-=lowbit(i))
for(int j=y; j>0; j-=lowbit(j))
ans+=c[i][j];
return ans;
}
void update(int x,int y,int p)
{
for(int i=x; i
for(int j=y; j
c[i][j]+=p;
}
int main()
{
int t,n,test,f=0;
int x1,x2,y1,y2;
char op;
scanf("%d",&t);
while(t--)
{
memset(c,0,sizeof(c));
if(f==1) printf("\n");
f=1;
scanf("%d%d",&n,&test);
while(test--)
{
scanf(" %c",&op);
if(op=='C')
{ www.2cto.com
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
update(x2+1,y2+1,1);
update(x1,y2+1,-1);
update(x2+1,y1,-1);
update(x1,y1,1);
}
else if(op=='Q')
{
scanf("%d%d",&x1,&y1);
printf("%d\n",sum(x1,y1)%2);
}
}
}
return 0;
}