# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98660 | DrumpfTheGodEmperor | Topovi (COCI15_topovi) | C++14 | 1525 ms | 40056 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
typedef pair<int, int> ii;
int n, k, p, ans = 0;
map<int, int> valr, valc, cntr, cntc;
map<ii, int> lol;
void delr(int x) {
ans -= cntr[x] * cntc[x];
cntr[x]--;
ans += cntr[x] * cntc[x];
}
void insr(int x) {
ans -= cntr[x] * cntc[x];
cntr[x]++;
ans += cntr[x] * cntc[x];
}
void delc(int x) {
ans -= cntr[x] * cntc[x];
cntc[x]--;
ans += cntr[x] * cntc[x];
}
void insc(int x) {
ans -= cntr[x] * cntc[x];
cntc[x]++;
ans += cntr[x] * cntc[x];
}
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> k >> p;
cntr[0] = cntc[0] = n;
ans = n * n;
fw (i, 0, k) {
int r, c, x;
cin >> r >> c >> x;
lol[ii(r, c)] = x;
delr(valr[r]);
valr[r] ^= x;
insr(valr[r]);
delc(valc[c]);
valc[c] ^= x;
insc(valc[c]);
}
while (p--) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
int x = lol[ii(r1, c1)];
lol[ii(r1, c1)] = 0;
lol[ii(r2, c2)] = x;
delr(valr[r1]);
delc(valc[c1]);
valr[r1] ^= x;
valc[c1] ^= x;
insr(valr[r1]);
insc(valc[c1]);
delr(valr[r2]);
delc(valc[c2]);
valr[r2] ^= x;
valc[c2] ^= x;
insr(valr[r2]);
insc(valc[c2]);
cout << n * n - ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |