Submission #624504

#TimeUsernameProblemLanguageResultExecution timeMemory
624504MilosMilutinovicTopovi (COCI15_topovi)C++14
120 / 120
1048 ms33560 KiB
/** * author: wxhtzdy * created: 07.08.2022 16:59:44 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, p; cin >> n >> k >> p; long long ans = n * n; map<int, int> cx; map<int, int> cy; cx[0] = n; cy[0] = n; map<int, int> xs; map<int, int> ys; map<pair<int, int>, int> val; function<void(int, int, int)> Add = [&](int x, int y, int v) { ans -= cx[ys[y]]; ans -= cy[xs[x]]; val[{x, y}] = v; cx[xs[x]] -= 1; cy[ys[y]] -= 1; xs[x] ^= v; ys[y] ^= v; cx[xs[x]] += 1; cy[ys[y]] += 1; ans += cx[ys[y]]; ans += cy[xs[x]]; }; function<void(int, int, int)> Remove = [&](int x, int y, int v) { ans -= cx[ys[y]]; ans -= cy[xs[x]]; val[{x, y}] = 0; cx[xs[x]] -= 1; cy[ys[y]] -= 1; xs[x] ^= v; ys[y] ^= v; cx[xs[x]] += 1; cy[ys[y]] += 1; ans += cx[ys[y]]; ans += cy[xs[x]]; }; for (int i = 0; i < k; i++) { int x, y, a; cin >> x >> y >> a; Add(x, y, a); } ans = 0; for (auto& p : cx) { ans += p.second * 1LL * cy[p.first]; } while (p--) { int xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb; Add(xb, yb, val[{xa, ya}]); Remove(xa, ya, val[{xa, ya}]); cout << n * 1LL * n - ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...