/**
* 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 * 1LL * 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
99 ms |
5216 KB |
Output is correct |
7 |
Correct |
76 ms |
4724 KB |
Output is correct |
8 |
Correct |
63 ms |
3832 KB |
Output is correct |
9 |
Correct |
63 ms |
3952 KB |
Output is correct |
10 |
Correct |
84 ms |
4108 KB |
Output is correct |
11 |
Correct |
931 ms |
33452 KB |
Output is correct |
12 |
Correct |
936 ms |
33480 KB |
Output is correct |
13 |
Correct |
940 ms |
33472 KB |
Output is correct |
14 |
Correct |
895 ms |
33456 KB |
Output is correct |
15 |
Correct |
941 ms |
33468 KB |
Output is correct |
16 |
Correct |
921 ms |
33424 KB |
Output is correct |
17 |
Correct |
876 ms |
33588 KB |
Output is correct |
18 |
Correct |
907 ms |
33512 KB |
Output is correct |
19 |
Correct |
917 ms |
33384 KB |
Output is correct |
20 |
Correct |
910 ms |
33392 KB |
Output is correct |