题目大意:有一个全零的矩阵,有两个操作。
1.改动(x1,y1)到(x2,y2)的数,使它们取异或。
2.查询(x,y)的状态。
思路:二维树状数组,区间改动,单点查询。
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1010 using namespace std; int cases; int cnt,asks; bool arr_tree[MAX][MAX]; char s[10]; inline void Fix(int x,int y); inline bool GetSum(int x,int y); int main() { for(cin >> cases;cases; --cases) { memset(arr_tree,false,sizeof(arr_tree)); scanf("%d%d",&cnt,&asks); for(int i = 1;i <= asks; ++i) { scanf("%s",s); if(s[0] == 'C') { int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); Fix(x2,y2),Fix(x1 - 1,y1 - 1); Fix(x2,y1 - 1),Fix(x1 - 1,y2); } else { int x,y; scanf("%d%d",&x,&y); printf("%d ",GetSum(x,y)); } } puts(""); } return 0; } inline void Fix(int x,int y) { for(int i = x;i;i -= i&-i) for(int j = y;j;j -= j&-j) arr_tree[i][j] ^= 1; } inline bool GetSum(int x,int y) { bool re = 0; for(int i = x;i <= cnt;i += i&-i) for(int j = y;j <= cnt;j += j&-j) re ^= arr_tree[i][j]; return re; }