제출 #956914

#제출 시각아이디문제언어결과실행 시간메모리
956914AriadnaTopovi (COCI15_topovi)C++14
30 / 120
386 ms65536 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAX_ROOKS = 2e5; int main() { int n, k, p; cin >> n >> k >> p; map<int, int> rows, columns; map<pair<int, int>, int> rooks; while (k--) { int r, c, x; cin >> r >> c >> x; --r; --c; rows[r] ^= x; columns[c] ^= x; rooks[{r, c}] = x; } ll total = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (((rows[i] ^ rooks[{i, j}]) ^ (columns[j] ^ rooks[{i, j}])) > 0) ++total; } } while (p--) { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; --r1; --r2; --c1; --c2; for (int i = 0; i < n; ++i) { if (i == c1) continue; if ((columns[i] ^ rows[r1]) == rooks[{r1, c1}]) --total; else if ((columns[i] ^ rows[r1]) == 0) ++total; } for (int i = 0; i < n; ++i) { if (i == r1) continue; if ((columns[c1] ^ rows[i]) == rooks[{r1, c1}]) --total; else if ((columns[c1] ^ rows[i]) == 0) ++total; } rows[r1] ^= rooks[{r1, c1}]; columns[c1] ^= rooks[{r1, c1}]; rooks[{r2, c2}] = rooks[{r1, c1}]; rooks[{r1, c1}] = 0; for (int i = 0; i < n; ++i) { if (i == c2) continue; if ((columns[i] ^ rows[r2]) == rooks[{r2, c2}]) --total; else if ((columns[i] ^ rows[r2]) == 0) ++total; } for (int i = 0; i < n; ++i) { if (i == r2) continue; if ((columns[c2] ^ rows[i]) == rooks[{r2, c2}]) --total; else if ((columns[c2] ^ rows[i]) == 0) ++total; } rows[r2] ^= rooks[{r2, c2}]; columns[c2] ^= rooks[{r2, c2}]; cout << total << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...