Submission #98710

#TimeUsernameProblemLanguageResultExecution timeMemory
98710TieuphongTopovi (COCI15_topovi)C++11
120 / 120
1989 ms33784 KiB
/***************************************************************************/ /********************** LANG TU HAO HOA **********************************/ /***************************************************************************/ #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) #define pii pair<int, int> #define sz(x) ((int) x.size()) #define PB push_back #define PF push_front #define MP make_pair #define ll long long #define F first #define S second #define maxc 1000000007 #define MOD 1000000007 #define base 107 #define eps 1e-6 #define pi acos(-1) #define N 100005 #define task "" #define remain(x) ((x > MOD) ? (x - MOD) : x) using namespace std; int n, p, k; ll res; map <int, int> r, c, demC, demR; map <pii, int> dd; void Calc(int x, int y, int fl) { res += fl * demC[r[x]]; res += fl * demR[c[y]]; if (r[x] == c[y]) res -= fl; } void Upd(int x, int y, int w) { Calc(x, y, -1); demR[r[x]]--, demC[c[y]]--; r[x] ^= w, c[y] ^= w; demR[r[x]]++, demC[c[y]]++; Calc(x, y, 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); //freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); cin >> n >> p >> k; res = 1ll*n*n; demR[0] = n; demC[0] = n; FOR(i, 1, p) { int u, v, w; cin >> u >> v >> w; Upd(u, v, w); dd[MP(u, v)] = w; } FOR(i, 1, k) { int x, y, u, v; cin >> x >> y >> u >> v; int w = dd[MP(x, y)]; dd[MP(x, y)] = 0; dd[MP(u, v)] = w; Upd(x, y, w); Upd(u, v, w); cout << 1ll*n*n - res << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...