Submission #960026

#TimeUsernameProblemLanguageResultExecution timeMemory
960026AriadnaTopovi (COCI15_topovi)C++14
120 / 120
1203 ms39944 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; map<int, int> xor_rows, xor_columns; map<int, int> cnt_rows, cnt_columns; map<pair<int, int>, int> rooks; void change(int r, int c, ll& total, int n) { total -= n-cnt_columns[xor_rows[r]]; total -= n-cnt_rows[xor_columns[c]]; if (xor_rows[r] ^ xor_columns[c]) ++total; cnt_rows[xor_rows[r]]--; xor_rows[r] ^= rooks[{r, c}]; cnt_rows[xor_rows[r]]++; cnt_columns[xor_columns[c]]--; xor_columns[c] ^= rooks[{r, c}]; cnt_columns[xor_columns[c]]++; total += n-cnt_columns[xor_rows[r]]; total += n-cnt_rows[xor_columns[c]]; if (xor_rows[r] ^ xor_columns[c]) --total; } int main() { int n, k, p; cin >> n >> k >> p; cnt_rows[0] = cnt_columns[0] = n; ll total = 0; while (k--) { int r, c, x; cin >> r >> c >> x; rooks[{r, c}] = x; change(r, c, total, n); } while (p--) { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; change(r1, c1, total, n); rooks[{r2, c2}] = rooks[{r1, c1}]; change(r2, c2, total, n); rooks[{r1, c1}] = 0; cout << total << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...