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 67 68 69 70 71 72 73 74 75
   | #include <bits/stdc++.h> #include <tr1/unordered_map> std::tr1::unordered_map<int, int> rcnt, ccnt; std::tr1::unordered_map<int, int> rxor, cxor; std::map<std::pair<int, int>, int> rook; const int iol = 1024 * 1024; char buf[iol], *ioh, *iot, ioc; bool iosig; inline char read() {     if (ioh == iot) {         iot = (ioh = buf) + fread(buf, 1, iol, stdin);         if (ioh == iot) return -1;     }     return *ioh++; } inline void read(int &x) {     for (ioc = read(); !isdigit(ioc); ioc = read());     x = 0;     for (; isdigit(ioc); ioc = read())         x = (x << 1) + (x << 3) + (ioc ^ '0');     if (iosig) x = -x; } int n, k, q; const int MAXN = 10010; long long sol; inline void moveRook(int r, int c, int val) {     using namespace std;     register int Rxor = rxor[r], Cxor = cxor[c];     sol -= n - ccnt[Rxor];     sol -= n - rcnt[Cxor];     if (Rxor != Cxor)         sol++;     rcnt[Rxor]--;     Rxor = rxor[r] ^= val;     rcnt[Rxor]++;     ccnt[Cxor]--;     Cxor = cxor[c] ^= val;     ccnt[Cxor]++;     sol += n - ccnt[Rxor];     sol += n - rcnt[Cxor];     if (Rxor != Cxor)         sol --;     rook[make_pair(r, c)] ^= val; } inline void init() {     read(n), read(k), read(q);     rcnt[0] = ccnt[0] = n;     for (register int i = 0; i < k; i++) {         register int r, c, val;         read(r), read(c), read(val);         r--, c--;         moveRook(r, c, val);     } } inline void solve() {     using namespace std;     while (q--) {         register int r1, c1, r2, c2;         read(r1), read(c1), read(r2), read(c2);         r1--, c1--, r2--, c2--;         register int rookValue = rook[make_pair(r1, c1)];         moveRook(r1, c1, rookValue);         moveRook(r2, c2, rookValue);         cout << sol << "\n";     } } int main() { #ifndef ONLINE_JUDGE     freopen("chess.in", "r", stdin); #endif     using namespace std;     init();     solve();     return 0; }
   |