Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 27355 | Accepted: 10003 |
Description
Input
Output
Sample Input
1 2 10 C 2 1 2 2 Q 2 2 C 2 1 2 1 Q 1 1 C 1 1 2 1 C 1 2 1 2 C 1 1 2 2 Q 1 1 C 1 1 2 1 Q 2 1
Sample Output
1 0 0 1
Source
#include
#include
#include
#include
using namespace std;
#define MAXN 1100
int c[MAXN][MAXN],n;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int num)//从大到小修改
{
for(int i=x; i>0; i-=lowbit(i))
for(int j=y; j>0; j-=lowbit(j))
c[i][j]+=num;
}
int sum(int x,int y)//从小到大求和
{
int res=0;
for(int i=x; i<=n; i+=lowbit(i))
for(int j=y; j<=n; j+=lowbit(j))
res+=c[i][j];
return res;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("G:/cbx/read.txt","r",stdin);
//freopen("G:/cbx/out.txt","w",stdout);
#endif
int T;
scanf("%d",&T);
while(T--)
{
int t;
char op[2];
memset(c,0,sizeof(c));
scanf("%d%d",&n,&t);
while(t--)
{
scanf("%s",op);
if(op[0]=='C')
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
update(x1-1,y1-1,1);
update(x2,y2,1);
update(x1-1,y2,-1);
update(x2,y1-1,-1);
}
else if(op[0]=='Q')
{
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",sum(x,y)%2);
}
}
printf("\n");
}
return 0;
}