1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <cstdlib> #include <cstdio> #include <iostream> #define N 1010 using namespace std;
int brod[N][N], t, n;
void clear() { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) brod[i][j] = 0; }
void update(int idx,int idy,int a) { for(int i = idy; i <= n; i+=(i&(-i))) for(int j=idx;j<=n;j+=(j&(-j))) brod[i][j]+=a; }
int query(int idx,int idy) { int sum=0; for(int i = idy; i > 0; i-=(i&(-i))) for(int j = idx; j > 0; j-=(j&(-j))) sum+=brod[i][j]; return sum; }
int main(int argc,char *argv[]) { scanf("%d", &t); while(t--){ int x1, x2, y1, y2, p; char c = '\n'; scanf("%d %d", &n, &p); clear(); while(p){ c = getchar(); if(c == 'C'){ p--; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); update(x1, y1, 1); if(y2 + 1 <= n) update(x1, y2+1, -1); if(x2 + 1 <= n) update(x2+1, y1, -1); if(y2 + 1 <= n && x2 + 1 <= n) update(x2+1, y2+1, 1);
}else if(c == 'Q'){ p--; scanf("%d %d",&x1,&y1); printf("%d\n", (query(x1, y1))%2); } } puts(""); } return 0; }
|