#include <stdio.h>
#include <string.h>
#define N 100000
#define Q 100000
#define M (N + Q * 2)
#define M_ (M * 2 + 1)
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[M], yy[M], ww[M_];
int compare_x(int i, int j) { return xx[i] - xx[j]; }
int compare_y(int i, int j) { return yy[i] - yy[j]; }
int compare_xy(int i, int j) { return xx[i] != xx[j] ? xx[i] - xx[j] : yy[i] - yy[j]; }
int compare_w(int i, int j) { return ww[i] - ww[j]; }
int (*compare)(int, int);
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = compare(ii[j], i_);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
void compress(int *xx, int n) {
static int ii[M_];
int i, x;
for (i = 0; i < n; i++)
ii[i] = i;
sort(ii, 0, n);
for (i = 0, x = 0; i < n; i++)
xx[ii[i]] = i + 1 == n || compare(ii[i + 1], ii[i]) != 0 ? x++ : x;
}
int main() {
static int ii_[M], aa[N], aa_[M], uu[M], vv[M], kk[M_], ll[M_];
int s, n, q, m, i;
long long ans;
scanf("%d%d%d", &s, &n, &q), m = n + q * 2;
for (i = 0; i < n; i++)
scanf("%d%d%d", &xx[i], &yy[i], &aa[i]);
for (i = 0; i < q * 2; i++)
scanf("%d%d", &xx[n + i], &yy[n + i]);
compare = compare_x, compress(xx, m);
compare = compare_y, compress(yy, m);
compare = compare_xy, compress(ii_, m);
for (i = 0; i < n; i++) {
int i_ = ii_[i];
aa_[i_] = aa[i];
ww[i << 1 | 0] = uu[xx[i]] ^= aa_[i_], ww[i << 1 | 1] = vv[yy[i]] ^= aa_[i_];
}
for (i = 0; i < q * 2; i++) {
int i_ = ii_[n + i];
if ((i & 1) == 1)
aa_[i_] = aa_[ii_[n + (i ^ 1)]];
ww[n + i << 1 | 0] = uu[xx[n + i]] ^= aa_[i_], ww[n + i << 1 | 1] = vv[yy[n + i]] ^= aa_[i_];
}
compare = compare_w, compress(ww, m * 2 + 1);
kk[0] = ll[0] = s;
memset(uu, 0, m * sizeof *uu), memset(vv, 0, m * sizeof *vv);
ans = 0;
for (i = 0; i < m; i++) {
int x = xx[i], y = yy[i];
ans += ll[uu[x]], kk[uu[x]]--, uu[x] = ww[i << 1 | 0], ans -= ll[uu[x]], kk[uu[x]]++;
ans += kk[vv[y]], ll[vv[y]]--, vv[y] = ww[i << 1 | 1], ans -= kk[vv[y]], ll[vv[y]]++;
if (i >= n && (i - n & 1) == 1)
printf("%lld\n", ans);
}
return 0;
}
Compilation message
topovi.c: In function 'main':
topovi.c:81:8: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
81 | ww[n + i << 1 | 0] = uu[xx[n + i]] ^= aa_[i_], ww[n + i << 1 | 1] = vv[yy[n + i]] ^= aa_[i_];
| ~~^~~
topovi.c:81:55: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
81 | ww[n + i << 1 | 0] = uu[xx[n + i]] ^= aa_[i_], ww[n + i << 1 | 1] = vv[yy[n + i]] ^= aa_[i_];
| ~~^~~
topovi.c:92:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
92 | if (i >= n && (i - n & 1) == 1)
| ~~^~~
topovi.c:62:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
62 | scanf("%d%d%d", &s, &n, &q), m = n + q * 2;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
topovi.c:64:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
64 | scanf("%d%d%d", &xx[i], &yy[i], &aa[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
topovi.c:66:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
66 | scanf("%d%d", &xx[n + i], &yy[n + i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
47 ms |
3216 KB |
Output is correct |
7 |
Correct |
37 ms |
2552 KB |
Output is correct |
8 |
Correct |
30 ms |
2124 KB |
Output is correct |
9 |
Correct |
32 ms |
2244 KB |
Output is correct |
10 |
Correct |
35 ms |
2492 KB |
Output is correct |
11 |
Correct |
339 ms |
19548 KB |
Output is correct |
12 |
Correct |
330 ms |
19520 KB |
Output is correct |
13 |
Correct |
336 ms |
19544 KB |
Output is correct |
14 |
Correct |
343 ms |
19560 KB |
Output is correct |
15 |
Correct |
342 ms |
19652 KB |
Output is correct |
16 |
Correct |
329 ms |
19652 KB |
Output is correct |
17 |
Correct |
331 ms |
19612 KB |
Output is correct |
18 |
Correct |
325 ms |
19524 KB |
Output is correct |
19 |
Correct |
329 ms |
19576 KB |
Output is correct |
20 |
Correct |
333 ms |
19652 KB |
Output is correct |