Submission #1015985

#TimeUsernameProblemLanguageResultExecution timeMemory
1015985May27_thTopovi (COCI15_topovi)C++17
6 / 120
2098 ms62212 KiB
#include<bits/stdc++.h> using namespace std; #define i64 long long #define i128 __int128 #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() map<int, i64> sumR, sumC, cntR, cntC; map<pair<int, int>, int> rock; void Solve(void) { int N, K, P; cin >> N >> K >> P; i64 ans = 0; cntR[0] = cntC[0] = N; auto Move = [&] (int r, int c) { ans = ans - (N - cntC[sumR[r]]); ans = ans - (N - cntR[sumC[c]]); if (sumR[r] != sumC[c]) ans ++; cntR[sumR[r]] --; cntC[sumC[c]] --; sumR[r] ^= rock[mp(r, c)]; sumC[c] ^= rock[mp(r, c)]; cntR[sumR[r]] ++; cntC[sumC[c]] ++; ans = ans + (N - cntC[sumR[r]]); ans = ans + (N - cntR[sumC[c]]); if (sumR[r] != sumC[c]) ans --; }; for (int i = 1; i <= N; i ++) { int r, c, x; cin >> r >> c >> x; rock[mp(r, c)] = x; Move(r, c); } while (P --) { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; Move(r1, c1); rock[mp(r2, c2)] = rock[mp(r1, c1)]; rock.erase(mp(r1, c1)); Move(r2, c2); cout << ans << "\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int Tests = 1; // cin >> Tests; while (Tests --) { Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...