#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
153 ms |
6336 KB |
Output is correct |
7 |
Correct |
124 ms |
5624 KB |
Output is correct |
8 |
Correct |
88 ms |
4676 KB |
Output is correct |
9 |
Correct |
103 ms |
4856 KB |
Output is correct |
10 |
Correct |
123 ms |
5032 KB |
Output is correct |
11 |
Correct |
1337 ms |
40056 KB |
Output is correct |
12 |
Correct |
1382 ms |
40056 KB |
Output is correct |
13 |
Correct |
1508 ms |
39880 KB |
Output is correct |
14 |
Correct |
1415 ms |
39960 KB |
Output is correct |
15 |
Correct |
1525 ms |
39944 KB |
Output is correct |
16 |
Correct |
1401 ms |
39928 KB |
Output is correct |
17 |
Correct |
1462 ms |
39964 KB |
Output is correct |
18 |
Correct |
1407 ms |
39984 KB |
Output is correct |
19 |
Correct |
1469 ms |
39900 KB |
Output is correct |
20 |
Correct |
1497 ms |
39956 KB |
Output is correct |