/*
ID: blackha5
TASK: test
LANG: C++
*/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define Maxn 100003
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
ll ans;
int n, k, p;
map <pii, int> E;
map <int, int> R, C;
map <int, int> cntr, cntc;
int main () {
//freopen ("file.in", "r", stdin);
//freopen ("file.out", "w", stdout);
//srand ((unsigned) time ( NULL ));
//int randomNumber = rand() % 10 + 1;
scanf ("%d%d%d", &n, &k, &p);
cntr[0] = n, cntc[0] = n;
for (int i = 1; i <= k; i++) {
int r, c, x;
scanf ("%d%d%d", &r, &c, &x);
E[{r, c}] = x;
cntr[R[r]] --, cntc[C[c]] --;
R[r] ^= x, C[c] ^= x;
cntr[R[r]] ++, cntc[C[c]] ++;
}
for (auto i: cntr)
ans += 1ll * (n - cntc[i.ff]) * i.ss;
while (p--) {
int r1, c1;
int r2, c2;
scanf ("%d%d%d%d", &r1, &c1, &r2, &c2);
int x = E[{r1, c1}];
E[{r1, c1}] = 0;
E[{r2, c2}] = x;
ans -= n - cntc[R[r1]];
ans -= n - cntr[C[c1]];
if (R[r1] != C[c1])
ans ++;
cntr[R[r1]] --, cntc[C[c1]] --;
R[r1] ^= x, C[c1] ^= x;
cntr[R[r1]] ++, cntc[C[c1]] ++;
ans += n - cntc[R[r1]];
ans += n - cntr[C[c1]];
if (R[r1] != C[c1])
ans --;
ans -= n - cntc[R[r2]];
ans -= n - cntr[C[c2]];
if (R[r2] != C[c2])
ans ++;
cntr[R[r2]] --, cntc[C[c2]] --;
R[r2] ^= x, C[c2] ^= x;
cntr[R[r2]] ++, cntc[C[c2]] ++;
ans += n - cntc[R[r2]];
ans += n - cntr[C[c2]];
if (R[r2] != C[c2])
ans --;
printf ("%lld\n", ans);
}
return 0;
}
Compilation message
topovi.cpp: In function 'int main()':
topovi.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", &n, &k, &p);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", &r, &c, &x);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:56:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d%d", &r1, &c1, &r2, &c2);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
564 KB |
Output is correct |
4 |
Correct |
3 ms |
652 KB |
Output is correct |
5 |
Correct |
1 ms |
652 KB |
Output is correct |
6 |
Correct |
167 ms |
6452 KB |
Output is correct |
7 |
Correct |
148 ms |
6452 KB |
Output is correct |
8 |
Correct |
104 ms |
6452 KB |
Output is correct |
9 |
Correct |
102 ms |
6732 KB |
Output is correct |
10 |
Correct |
123 ms |
7516 KB |
Output is correct |
11 |
Correct |
1500 ms |
42648 KB |
Output is correct |
12 |
Correct |
1497 ms |
48736 KB |
Output is correct |
13 |
Correct |
1547 ms |
54748 KB |
Output is correct |
14 |
Correct |
1816 ms |
60804 KB |
Output is correct |
15 |
Runtime error |
1780 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
16 |
Runtime error |
1745 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
17 |
Runtime error |
1694 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
18 |
Runtime error |
1494 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
19 |
Runtime error |
1492 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
20 |
Runtime error |
1785 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |