//现在知道的树状数组有两种写法,一个适用擦边查点,一种适用擦点查边 //擦点查边的写法比较普通,arr[i] 存的就是i管辖范围内的sum //擦边查点反过来写,此时,插入t到[a,b]相当于插入-t到[0,a-1] 插入t到[0,b] //插入时,arr[i]表示管辖范围内的影响值,当不是全部,实际上查询要不断+lowbit加到暴 //二维的也只是插入一个大矩形,恢复三个小矩形的过程 #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define lowbit(x) (x&(-x)) int x, n, m; char cmd[5]; int x1, x2, y1, y2; bool arr[1001][1001]; int t = 1; void updata(int x, int y) { while(x) { int t = y; while(t) { arr[x][t] ^= true; t -= lowbit(t); } x -= lowbit(x); } } bool query(int x, int y) { bool result =false; while(x <= n) { int t = y; while(t <= n) { result ^= arr[x][t]; t += lowbit(t); } x += lowbit(x); } return result; } int main() { //freopen("1.txt", "r", stdin); scanf("%d", &x); while(x--) { if(t++ > 1) printf("\n"); memset(arr, false, sizeof(arr)); scanf("%d %d", &n, &m); while(m--) { scanf("%s", cmd); if(cmd[0] == 'C') { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); updata(x2, y2); updata(x1-1,y1-1); updata(x1-1,y2); updata(x2,y1-1); } else { scanf("%d %d", &x1, &y1); printf("%d\n", (query(x1,y1)?1:0)); } } } }