#include<bits/stdc++.h>
using namespace std;
int n, k, p;
map < int, int > a, b, aa, bb;
map < pair < int, int >, int > q;
long long ans;
inline void upd(int x, int y, int z){
ans -= (n - aa[a[x]]);
ans -= (n - bb[b[y]]);
aa[b[y]] -= 1;
bb[a[x]] -= 1;
a[x] ^= z;
b[y] ^= z;
aa[b[y]] += 1;
bb[a[x]] += 1;
ans += (n - aa[a[x]]);
ans += (n - bb[b[y]]);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k >> p;
aa[0] = bb[0] = n;
for(int i = 1; i <= k; i++){
int x, y, z;
cin >> x >> y >> z;
q[make_pair(x, y)] = z;
upd(x, y, z);
}
while(p--){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int z = q[make_pair(x1, y1)];
upd(x1, y1, z);
upd(x2, y2, z);
q[make_pair(x2, y2)] = q[make_pair(x1, y1)];
cout << ans << "\n";
}
}
/**
2 2 2
1 1 1
2 2 1
2 2 2 1
1 1 1 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
137 ms |
6136 KB |
Output is correct |
7 |
Correct |
131 ms |
5624 KB |
Output is correct |
8 |
Correct |
101 ms |
4524 KB |
Output is correct |
9 |
Correct |
101 ms |
4600 KB |
Output is correct |
10 |
Correct |
103 ms |
4728 KB |
Output is correct |
11 |
Correct |
1470 ms |
39664 KB |
Output is correct |
12 |
Correct |
1453 ms |
39612 KB |
Output is correct |
13 |
Correct |
1381 ms |
39544 KB |
Output is correct |
14 |
Correct |
1352 ms |
39452 KB |
Output is correct |
15 |
Correct |
1432 ms |
39672 KB |
Output is correct |
16 |
Correct |
1512 ms |
39484 KB |
Output is correct |
17 |
Correct |
1517 ms |
39596 KB |
Output is correct |
18 |
Correct |
1475 ms |
39500 KB |
Output is correct |
19 |
Correct |
1385 ms |
39624 KB |
Output is correct |
20 |
Correct |
1346 ms |
39544 KB |
Output is correct |