思路:
二维树状数组。点修改区间查询转化为区间修改点查询。
http://blog.csdn.net/z309241990/article/details/9615259
http://blog.csdn.net/acm_BaiHuzi/article/details/46819049
实现:
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 const int MAXN = 1005; 5 int bit[MAXN][MAXN], x, n, t; 6 7 int lowbit(int x) 8 { 9 return x & -x; 10 } 11 12 void add(int x, int y, int d) 13 { 14 for (int i = x; i <= n; i += lowbit(i)) 15 { 16 for (int j = y; j <= n; j += lowbit(j)) 17 { 18 bit[i][j] += d; 19 } 20 } 21 } 22 23 int sum(int x, int y) 24 { 25 int ans = 0; 26 for (int i = x; i > 0; i -= lowbit(i)) 27 { 28 for (int j = y; j > 0; j -= lowbit(j)) 29 { 30 ans += bit[i][j]; 31 } 32 } 33 return ans; 34 } 35 36 int main() 37 { 38 ios::sync_with_stdio(false); 39 cin >> x; 40 char c; int x1, y1, x2, y2; 41 while (x--) 42 { 43 memset(bit, 0, sizeof bit); 44 cin >> n >> t; 45 for (int i = 0; i < t; i++) 46 { 47 cin >> c; 48 if (c == ‘Q‘) 49 { 50 cin >> x1 >> y1; 51 cout << (sum(x1, y1) & 1) << endl; 52 } 53 else 54 { 55 cin >> x1 >> y1 >> x2 >> y2; 56 add(x1, y1, 1); 57 add(x1, y2 + 1, -1); 58 add(x2 + 1, y1, -1); 59 add(x2 + 1, y2 + 1, 1); 60 } 61 } 62 cout << endl; 63 } 64 return 0; 65 }