#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <map>
using namespace std;
int n, k, q, r1, c1, r2, c2, x;
long long ans;
map<int, int> row, col, cntr, cntc;
map<pair<int, int>, int> mp;
inline void func(int r, int c, int val) {
ans -= n - cntc[row[r]];
ans -= n - cntr[col[c]];
if (row[r] != col[c])
ans++;
cntr[row[r]]--;
row[r] ^= val;
cntr[row[r]]++;
cntc[col[c]]--;
col[c] ^= val;
cntc[col[c]]++;
ans += n - cntc[row[r]];
ans += n - cntr[col[c]];
if (row[r] != col[c])
ans--;
}
int main() {
scanf("%d %d %d", &n, &k, &q);
cntr[0] = n;
cntc[0] = n;
for (int i = 0; i < k; i++) {
scanf("%d %d %d", &r1, &c1, &x);
mp[{r1, c1}] = x;
func(r1, c1, x);
}
while (q--) {
scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
x = mp[{r1, c1}];
mp.erase({r1, c1});
mp[{r2, c2}] = x;
func(r1, c1, x);
func(r2, c2, x);
printf("%lld\n", ans);
}
return 0;
}
Compilation message
topovi.cpp: In function 'int main()':
topovi.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &k, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &r1, &c1, &x);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:43:14: 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 |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
149 ms |
4472 KB |
Output is correct |
7 |
Correct |
119 ms |
4348 KB |
Output is correct |
8 |
Correct |
97 ms |
3704 KB |
Output is correct |
9 |
Correct |
96 ms |
3680 KB |
Output is correct |
10 |
Correct |
111 ms |
3708 KB |
Output is correct |
11 |
Correct |
1278 ms |
27676 KB |
Output is correct |
12 |
Correct |
1286 ms |
27784 KB |
Output is correct |
13 |
Correct |
1258 ms |
27768 KB |
Output is correct |
14 |
Correct |
1274 ms |
27768 KB |
Output is correct |
15 |
Correct |
1281 ms |
27600 KB |
Output is correct |
16 |
Correct |
1261 ms |
27508 KB |
Output is correct |
17 |
Correct |
1242 ms |
27640 KB |
Output is correct |
18 |
Correct |
1257 ms |
27512 KB |
Output is correct |
19 |
Correct |
1258 ms |
27512 KB |
Output is correct |
20 |
Correct |
1257 ms |
27640 KB |
Output is correct |