forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2155 - Matrix.cpp
66 lines (47 loc) · 1.26 KB
/
2155 - Matrix.cpp
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
#include <iostream>
#include <cstring>
using namespace std;
int N;
char bit[1002][1002];
void update(int x, int y){
++x; ++y;
for(int qx = x;qx <= N + 1;qx += qx & -qx)
for(int qy = y;qy <= N + 1;qy += qy & -qy)
bit[qx][qy] ^= 1;
}
int query(int x, int y){
++x; ++y;
int ret = 0;
for(int qx = x;qx > 0;qx -= qx & -qx)
for(int qy = y;qy > 0;qy -= qy & -qy)
ret ^= bit[qx][qy];
return ret;
}
int main(){
ios::sync_with_stdio(false);
int T,Q;
int x1,y1,x2,y2,x,y;
char op;
bool first = true;
cin >> T;
while(T--){
cin >> N >> Q;
memset(bit,0,sizeof bit);
if(!first) cout << '\n';
first = false;
while(Q--){
cin >> op;
if(op == 'C'){
cin >> x1 >> y1 >> x2 >> y2;
update(x2,y2);
update(x2,y1 - 1);
update(x1 - 1,y2);
update(x1 - 1,y1 - 1);
}else{
cin >> x >> y;
cout << (query(N,N) ^ query(x - 1,N) ^ query(N,y - 1) ^ query(x - 1,y - 1)) << '\n';
}
}
}
return 0;
}