水水的二维树状数组,代码写搓了,找了好久的错。。。
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#define maxn 1005
#define eps 1e-7
#define mod 1000000007
#define INF 99999999
#define lowbit(x) (x&(-x))
typedef long long LL;
using namespace std;
int tree[maxn][maxn];
char s[10];
int n, m;
void add(int xx1, int yy1, int xx2, int yy2)
{
int i, j;
for(i=xx1;i<=n;i+=lowbit(i))
for(j=yy1;j<=n;j+=lowbit(j))
tree[i][j]+=1;
for(i=xx2+1;i<=n;i+=lowbit(i))
for(j=yy2+1;j<=n;j+=lowbit(j))
tree[i][j]+=1;
for(i=xx2+1;i<=n;i+=lowbit(i))
for(j=yy1;j<=n;j+=lowbit(j))
tree[i][j]-=1;
for(i=xx1;i<=n;i+=lowbit(i))
for(j=yy2+1;j<=n;j+=lowbit(j))
tree[i][j]-=1;
}
int query(int x, int y)
{
int i, j, ans=0;
for(i=x;i>0;i-=lowbit(i))
for(j=y;j>0;j-=lowbit(j))
ans+=tree[i][j];
return ans;
}
void solve(void)
{
int x, y, xx1, yy1, xx2, yy2;
memset(tree, 0, sizeof tree);
while(m--){
scanf("%s", s);
if(s[0]=='Q'){
scanf("%d%d",&x,&y);
printf("%d\n", query(x, y)%2);
}
else{
scanf("%d%d%d%d",&xx1,&yy1,&xx2,&yy2);
add(xx1, yy1, xx2, yy2);
}
}
}
int main(void)
{
int _;
while(scanf("%d",&_)!=EOF){
while(_--){
scanf("%d%d",&n,&m);
solve();
if(_) printf("\n");
}
}
return 0;
}