#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define i128 __int128
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
map<int, int> sumR, sumC, cntR, cntC;
map<pair<int, int>, int> rock;
void Solve(void) {
int N, K, P; cin >> N >> K >> P;
i64 ans = 0;
cntR[0] = cntC[0] = N;
auto Move = [&] (int r, int c) {
ans = ans - (N - cntC[sumR[r]]);
ans = ans - (N - cntR[sumC[c]]);
if (sumR[r] != sumC[c]) ans ++;
cntR[sumR[r]] --;
cntC[sumC[c]] --;
sumR[r] ^= rock[mp(r, c)];
sumC[c] ^= rock[mp(r, c)];
cntR[sumR[r]] ++;
cntC[sumC[c]] ++;
ans = ans + (N - cntC[sumR[r]]);
ans = ans + (N - cntR[sumC[c]]);
if (sumR[r] != sumC[c]) ans --;
};
for (int i = 1; i <= K; i ++) {
int r, c, x; cin >> r >> c >> x;
rock[mp(r, c)] = x;
Move(r, c);
}
while (P --) {
int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
Move(r1, c1);
rock[mp(r2, c2)] = rock[mp(r1, c1)];
rock.erase(mp(r1, c1));
Move(r2, c2);
cout << ans << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(10);
int Tests = 1; // cin >> Tests;
while (Tests --) {
Solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
89 ms |
4164 KB |
Output is correct |
7 |
Correct |
70 ms |
3920 KB |
Output is correct |
8 |
Correct |
54 ms |
3412 KB |
Output is correct |
9 |
Correct |
67 ms |
3340 KB |
Output is correct |
10 |
Correct |
67 ms |
3348 KB |
Output is correct |
11 |
Correct |
644 ms |
27216 KB |
Output is correct |
12 |
Correct |
658 ms |
27216 KB |
Output is correct |
13 |
Correct |
728 ms |
27272 KB |
Output is correct |
14 |
Correct |
703 ms |
27220 KB |
Output is correct |
15 |
Correct |
697 ms |
27216 KB |
Output is correct |
16 |
Correct |
749 ms |
27148 KB |
Output is correct |
17 |
Correct |
701 ms |
27136 KB |
Output is correct |
18 |
Correct |
696 ms |
27220 KB |
Output is correct |
19 |
Correct |
614 ms |
27216 KB |
Output is correct |
20 |
Correct |
651 ms |
27220 KB |
Output is correct |