#include <stdio.h>
#define N 200000
#define Q 200000
#define M (N * 2 + Q)
#define L 60 /* L = ceil(log2(10^18 + 1)) */
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
long long rev(long long a) {
int l;
long long b;
b = 0;
for (l = L - 1; l >= 0; l--)
if ((a & 1LL << l) != 0)
b |= 1LL << L - 1 - l;
return b;
}
long long *ww;
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = ww[hh[j]] != ww[h] ? (ww[hh[j]] < ww[h] ? -1 : 1) : hh[j] - h;
if (c == 0)
j++;
else if (c < 0) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
}
sort(hh, l, i);
l = k;
}
}
int ft[M];
void update(int i, int n, int x) {
while (i < n) {
ft[i] += x;
i |= i + 1;
}
}
int query(int i) {
int x = 0;
while (i >= 0) {
x += ft[i];
i &= i + 1, i--;
}
return x;
}
int main() {
static long long xx[M], yy[M];
static int cc[N], hh[M], ans[Q];
int n, m, q, h, h_, i, x;
scanf("%d%d", &n, &q);
for (i = 0; i < n; i++) {
long long x, y, u, v;
scanf("%lld%lld%d", &x, &y, &cc[i]), x = rev(x), y = rev(y), u = x & -x, v = y & -y;
xx[i << 1 | 0] = x - u + 1, xx[i << 1 | 1] = x + u;
yy[i << 1 | 0] = y - v + 1, yy[i << 1 | 1] = y + v;
}
for (h = 0; h < q; h++) {
long long x, y;
scanf("%lld%lld", &x, &y), x = rev(x), y = rev(y);
xx[n * 2 + h] = x, yy[n * 2 + h] = y;
}
m = n * 2 + q;
for (h = 0; h < m; h++)
hh[h] = h;
ww = xx, sort(hh, 0, m);
for (h = 0, x = 0; h < m; h++)
xx[hh[h]] = h + 1 == m || xx[hh[h + 1]] != xx[hh[h]] ? x++ : x;
ww = yy, sort(hh, 0, m);
for (h = 0; h < m; h++) {
h_ = hh[h];
if (h_ < n * 2) {
i = h_ >> 1;
update(xx[h_], m, cc[i]), update(xx[h_ ^ 1], m, -cc[i]);
} else
ans[h_ - n * 2] = query(xx[h_]);
}
for (h = 0; h < q; h++)
printf("%d\n", ans[h]);
return 0;
}
Compilation message
Main.c: In function 'rev':
Main.c:21:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
21 | b |= 1LL << L - 1 - l;
| ^
Main.c: In function 'main':
Main.c:73:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%d%d", &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:77:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | scanf("%lld%lld%d", &x, &y, &cc[i]), x = rev(x), y = rev(y), u = x & -x, v = y & -y;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:84:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | scanf("%lld%lld", &x, &y), x = rev(x), y = rev(y);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8620 KB |
Output is correct |
2 |
Correct |
6 ms |
8636 KB |
Output is correct |
3 |
Correct |
6 ms |
8796 KB |
Output is correct |
4 |
Correct |
5 ms |
8540 KB |
Output is correct |
5 |
Correct |
5 ms |
8612 KB |
Output is correct |
6 |
Correct |
5 ms |
8628 KB |
Output is correct |
7 |
Correct |
5 ms |
8632 KB |
Output is correct |
8 |
Correct |
5 ms |
8540 KB |
Output is correct |
9 |
Correct |
5 ms |
8540 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
5 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
472 ms |
29504 KB |
Output is correct |
2 |
Correct |
471 ms |
29376 KB |
Output is correct |
3 |
Correct |
466 ms |
28652 KB |
Output is correct |
4 |
Correct |
438 ms |
28604 KB |
Output is correct |
5 |
Correct |
412 ms |
25272 KB |
Output is correct |
6 |
Correct |
415 ms |
25376 KB |
Output is correct |
7 |
Correct |
425 ms |
25196 KB |
Output is correct |
8 |
Correct |
406 ms |
25256 KB |
Output is correct |
9 |
Correct |
408 ms |
25172 KB |
Output is correct |
10 |
Correct |
416 ms |
25232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
206 ms |
20696 KB |
Output is correct |
3 |
Correct |
213 ms |
20692 KB |
Output is correct |
4 |
Correct |
194 ms |
19996 KB |
Output is correct |
5 |
Correct |
225 ms |
19920 KB |
Output is correct |
6 |
Correct |
188 ms |
18832 KB |
Output is correct |
7 |
Correct |
187 ms |
19028 KB |
Output is correct |
8 |
Correct |
222 ms |
18888 KB |
Output is correct |
9 |
Correct |
204 ms |
19028 KB |
Output is correct |
10 |
Correct |
190 ms |
18832 KB |
Output is correct |
11 |
Correct |
222 ms |
18972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8620 KB |
Output is correct |
2 |
Correct |
6 ms |
8636 KB |
Output is correct |
3 |
Correct |
6 ms |
8796 KB |
Output is correct |
4 |
Correct |
5 ms |
8540 KB |
Output is correct |
5 |
Correct |
5 ms |
8612 KB |
Output is correct |
6 |
Correct |
5 ms |
8628 KB |
Output is correct |
7 |
Correct |
5 ms |
8632 KB |
Output is correct |
8 |
Correct |
5 ms |
8540 KB |
Output is correct |
9 |
Correct |
5 ms |
8540 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
5 ms |
8540 KB |
Output is correct |
12 |
Correct |
472 ms |
29504 KB |
Output is correct |
13 |
Correct |
471 ms |
29376 KB |
Output is correct |
14 |
Correct |
466 ms |
28652 KB |
Output is correct |
15 |
Correct |
438 ms |
28604 KB |
Output is correct |
16 |
Correct |
412 ms |
25272 KB |
Output is correct |
17 |
Correct |
415 ms |
25376 KB |
Output is correct |
18 |
Correct |
425 ms |
25196 KB |
Output is correct |
19 |
Correct |
406 ms |
25256 KB |
Output is correct |
20 |
Correct |
408 ms |
25172 KB |
Output is correct |
21 |
Correct |
416 ms |
25232 KB |
Output is correct |
22 |
Correct |
1 ms |
8536 KB |
Output is correct |
23 |
Correct |
206 ms |
20696 KB |
Output is correct |
24 |
Correct |
213 ms |
20692 KB |
Output is correct |
25 |
Correct |
194 ms |
19996 KB |
Output is correct |
26 |
Correct |
225 ms |
19920 KB |
Output is correct |
27 |
Correct |
188 ms |
18832 KB |
Output is correct |
28 |
Correct |
187 ms |
19028 KB |
Output is correct |
29 |
Correct |
222 ms |
18888 KB |
Output is correct |
30 |
Correct |
204 ms |
19028 KB |
Output is correct |
31 |
Correct |
190 ms |
18832 KB |
Output is correct |
32 |
Correct |
222 ms |
18972 KB |
Output is correct |
33 |
Correct |
528 ms |
32796 KB |
Output is correct |
34 |
Correct |
525 ms |
32788 KB |
Output is correct |
35 |
Correct |
518 ms |
30128 KB |
Output is correct |
36 |
Correct |
495 ms |
30124 KB |
Output is correct |
37 |
Correct |
454 ms |
26772 KB |
Output is correct |
38 |
Correct |
460 ms |
26684 KB |
Output is correct |
39 |
Correct |
463 ms |
26684 KB |
Output is correct |
40 |
Correct |
445 ms |
26688 KB |
Output is correct |
41 |
Correct |
480 ms |
26944 KB |
Output is correct |
42 |
Correct |
477 ms |
26680 KB |
Output is correct |