#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int tree[1005][1005]={0},n;
int offline()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
return 0;
}
int exit()
{
fclose(stdin);
fclose(stdout);
return 0;
}
int lowbit(int t)
{
return t&(-t);
}
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+=tree[i][j];
return ans;
}
void plus(int x,int y,int num)
{
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j))
tree[i][j]+=num;
}
int main()
{
offline();
int cnt,t,a,b,x1,x2,y1,y2;
char order;
scanf("%d",&cnt);
while(cnt--)
{
memset(tree,0,sizeof(tree));
scanf("%d %d",&n,&t);
getchar();
while(t--)
{
scanf("%c",&order);
if(order=='C')
{
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
getchar();
plus(x1,y1,1);
plus(x1,y2+1,1);
plus(x2+1,y1,1);
plus(x2+1,y2+1,1);
}
else
{
scanf("%d %d",&a,&b);
getchar();
printf("%d\n",sum(a,b)%2);
}
}
printf("\n");
}
exit();
return 0;
}
POJ2155
2015-03-28 17:43:12 By zmhx2
评论
Trinkle
1. lowbit别用函数会慢,直接算
i+=i&-i
2. 用bool就可以了,+1直接变成^1
- 2015-03-30 12:50:17
发表评论
可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。