区间翻转, 单点查询, 查询操作我真是不太明白......
1 #include <iostream> 2 #include <vector> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <cmath> 7 #include <map> 8 #include <set> 9 #include <string> 10 #include <queue> 11 using namespace std; 12 #define pb(x) push_back(x) 13 #define ll long long 14 #define mk(x, y) make_pair(x, y) 15 #define lson l, m, rt<<1 16 #define mem(a) memset(a, 0, sizeof(a)) 17 #define rson m+1, r, rt<<1|1 18 #define mem1(a) memset(a, -1, sizeof(a)) 19 #define mem2(a) memset(a, 0x3f, sizeof(a)) 20 #define rep(i, a, n) for(int i = a; i<n; i++) 21 #define ull unsigned long long 22 typedef pair<int, int> pll; 23 const double PI = acos(-1.0); 24 const double eps = 1e-8; 25 const int mod = 1e9+7; 26 const int inf = 1061109567; 27 const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; 28 const int maxn = 1005; 29 int sum[maxn<<2][maxn<<2], n, ans; 30 void pushUp(int pos, int rt) { 31 sum[pos][rt] = sum[pos][rt<<1]+sum[pos][rt<<1|1]; 32 } 33 void sub_update(int pos, int L, int R, int l, int r, int rt) { 34 if(L<=l&&R>=r) { 35 sum[pos][rt]^=1; 36 return ; 37 } 38 int m = l+r>>1; 39 if(L<=m) 40 sub_update(pos, L, R, lson); 41 if(R>m) 42 sub_update(pos, L, R, rson); 43 } 44 void update(int LX, int RX, int LY, int RY, int l, int r, int rt) { 45 if(LX<=l&&RX>=r) { 46 sub_update(rt, LY, RY, 1, n, 1); 47 return ; 48 } 49 int m = l+r>>1; 50 if(LX<=m) 51 update(LX, RX, LY, RY, lson); 52 if(RX>m) 53 update(LX, RX, LY, RY, rson); 54 } 55 void sub_query(int pos, int p, int l, int r, int rt) { 56 ans ^= sum[pos][rt]; 57 if(l == r) 58 return ; 59 int m = l+r>>1; 60 if(p<=m) 61 return sub_query(pos, p, lson); 62 else 63 return sub_query(pos, p, rson); 64 } 65 void query(int x, int y, int l, int r, int rt) { 66 sub_query(rt, y, 1, n, 1); 67 if(l == r) 68 return ; 69 int m = l+r>>1; 70 if(x<=m) 71 return query(x, y, lson); 72 else 73 return query(x, y, rson); 74 } 75 int main() 76 { 77 int t, q, lx, rx, ly, ry; 78 cin>>t; 79 char c[2]; 80 while(t--) { 81 mem(sum); 82 scanf("%d%d", &n, &q); 83 while(q--) { 84 scanf("%s", c); 85 if(c[0] == 'C') { 86 scanf("%d%d%d%d", &lx, &ly, &rx, &ry); 87 update(lx, rx, ly, ry, 1, n, 1); 88 } else { 89 scanf("%d%d", &lx, &ly); 90 ans = 0; 91 query(lx, ly, 1, n, 1); 92 printf("%d ", ans); 93 } 94 } 95 if(t) 96 puts(""); 97 } 98 }