#include<cstdio>
#include<algorithm>
#include<vector>
#define SZ 131072
using namespace std;
int n;
struct Query {
int a, b, c, num;
bool operator<(const Query &p)const {
return c < p.c;
}
}w[101000], U[101000];
int A[201000], B[201000], CA, CB, Res[101000];
struct IT2D {
vector<int>V[SZ + SZ];
vector<int>BIT[SZ + SZ];
void Build(int nd, int b, int e) {
V[nd].resize(e - b + 1);
BIT[nd].resize(e - b + 2);
for (int i = b; i <= e; i++) {
V[nd][i - b] = w[i].b;
}
sort(V[nd].begin(), V[nd].end());
if (b == e)return;
int m = (b + e) >> 1;
Build(nd * 2, b, m);
Build(nd * 2 + 1, m + 1, e);
}
void Put2(int nd, int y) {
int x = lower_bound(V[nd].begin(), V[nd].end(), y) - V[nd].begin();
x++;
int sz = V[nd].size();
while (x <= sz) {
BIT[nd][x]++;
x += (x&-x);
}
}
void Put(int nd, int b, int e, int x, int y) {
Put2(nd, y);
if (b == e) {
return;
}
int m = (b + e) >> 1;
if (x <= m)Put(nd * 2, b, m, x, y);
else Put(nd * 2 + 1, m + 1, e, x, y);
}
int Sum(int nd, int x) {
int r = 0;
while (x) {
r += BIT[nd][x];
x -= (x&-x);
}
return r;
}
int Get2(int nd, int y) {
int x = lower_bound(V[nd].begin(), V[nd].end(), y) - V[nd].begin();
int sz = V[nd].size();
return Sum(nd, sz) - Sum(nd, x);
}
int Get(int nd, int b, int e, int s, int l, int y) {
if (s > l)return 0;
if (b == s && e == l) {
return Get2(nd, y);
}
int m = (b + e) >> 1, r = 0;
if (s <= m)r += Get(nd * 2, b, m, s, min(m, l), y);
if (l > m)r += Get(nd * 2 + 1, m + 1, e, max(m + 1, s), l, y);
return r;
}
}TT;
int main() {
int i, Q;
scanf("%d%d", &n, &Q);
for (i = 1; i <= n; i++) {
scanf("%d%d", &w[i].a, &w[i].b);
w[i].c = w[i].a + w[i].b;
A[++CA] = w[i].a;
B[++CB] = w[i].b;
}
for (i = 1; i <= Q; i++) {
scanf("%d%d%d", &U[i].a, &U[i].b, &U[i].c);
U[i].num = i;
}
sort(A + 1, A + CA + 1);
sort(B + 1, B + CB + 1);
for (i = 1; i <= n; i++) {
w[i].a = lower_bound(A + 1, A + CA + 1, w[i].a) - A;
w[i].b = lower_bound(B + 1, B + CB + 1, w[i].b) - B;
}
for (i = 1; i <= Q; i++) {
U[i].a = lower_bound(A + 1, A + CA + 1, U[i].a) - A;
U[i].b = lower_bound(B + 1, B + CB + 1, U[i].b) - B;
}
for (i = 1; i <= n; i++) {
swap(w[i].a, w[i].c);
}
sort(w + 1, w + n + 1);
for (i = 1; i <= n; i++) {
swap(w[i].a, w[i].c);
w[i].num = i;
w[i].a = i;
}
TT.Build(1, 1, n);
sort(w + 1, w + n + 1);
sort(U + 1, U + Q + 1);
int pv = n;
for (i = Q; i >= 1; i--) {
while (pv >= 1 && w[pv].c >= U[i].c) {
TT.Put(1, 1, n, w[pv].a, w[pv].b);
pv--;
}
Res[U[i].num] = TT.Get(1, 1, n, U[i].a, n, U[i].b);
}
for (i = 1; i <= Q; i++)printf("%d\n", Res[i]);
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &Q);
~~~~~^~~~~~~~~~~~~~~~
examination.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &w[i].a, &w[i].b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &U[i].a, &U[i].b, &U[i].c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12672 KB |
Output is correct |
2 |
Correct |
15 ms |
12672 KB |
Output is correct |
3 |
Correct |
14 ms |
12672 KB |
Output is correct |
4 |
Correct |
15 ms |
12736 KB |
Output is correct |
5 |
Correct |
15 ms |
12644 KB |
Output is correct |
6 |
Correct |
13 ms |
12664 KB |
Output is correct |
7 |
Correct |
30 ms |
13540 KB |
Output is correct |
8 |
Correct |
25 ms |
13568 KB |
Output is correct |
9 |
Correct |
26 ms |
13568 KB |
Output is correct |
10 |
Correct |
23 ms |
13440 KB |
Output is correct |
11 |
Correct |
24 ms |
13440 KB |
Output is correct |
12 |
Correct |
19 ms |
13440 KB |
Output is correct |
13 |
Correct |
24 ms |
13568 KB |
Output is correct |
14 |
Correct |
26 ms |
13532 KB |
Output is correct |
15 |
Correct |
29 ms |
13440 KB |
Output is correct |
16 |
Correct |
22 ms |
13440 KB |
Output is correct |
17 |
Correct |
24 ms |
13436 KB |
Output is correct |
18 |
Correct |
18 ms |
13440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
43256 KB |
Output is correct |
2 |
Correct |
1075 ms |
43280 KB |
Output is correct |
3 |
Correct |
990 ms |
43356 KB |
Output is correct |
4 |
Correct |
559 ms |
42692 KB |
Output is correct |
5 |
Correct |
800 ms |
42616 KB |
Output is correct |
6 |
Correct |
565 ms |
41832 KB |
Output is correct |
7 |
Correct |
905 ms |
43284 KB |
Output is correct |
8 |
Correct |
902 ms |
43344 KB |
Output is correct |
9 |
Correct |
781 ms |
43128 KB |
Output is correct |
10 |
Correct |
713 ms |
42492 KB |
Output is correct |
11 |
Correct |
433 ms |
42340 KB |
Output is correct |
12 |
Correct |
266 ms |
41440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
923 ms |
43256 KB |
Output is correct |
2 |
Correct |
1075 ms |
43280 KB |
Output is correct |
3 |
Correct |
990 ms |
43356 KB |
Output is correct |
4 |
Correct |
559 ms |
42692 KB |
Output is correct |
5 |
Correct |
800 ms |
42616 KB |
Output is correct |
6 |
Correct |
565 ms |
41832 KB |
Output is correct |
7 |
Correct |
905 ms |
43284 KB |
Output is correct |
8 |
Correct |
902 ms |
43344 KB |
Output is correct |
9 |
Correct |
781 ms |
43128 KB |
Output is correct |
10 |
Correct |
713 ms |
42492 KB |
Output is correct |
11 |
Correct |
433 ms |
42340 KB |
Output is correct |
12 |
Correct |
266 ms |
41440 KB |
Output is correct |
13 |
Correct |
924 ms |
43736 KB |
Output is correct |
14 |
Correct |
929 ms |
43800 KB |
Output is correct |
15 |
Correct |
935 ms |
43388 KB |
Output is correct |
16 |
Correct |
605 ms |
42852 KB |
Output is correct |
17 |
Correct |
851 ms |
42920 KB |
Output is correct |
18 |
Correct |
548 ms |
41848 KB |
Output is correct |
19 |
Correct |
1006 ms |
43840 KB |
Output is correct |
20 |
Correct |
1020 ms |
43664 KB |
Output is correct |
21 |
Correct |
985 ms |
43896 KB |
Output is correct |
22 |
Correct |
680 ms |
42360 KB |
Output is correct |
23 |
Correct |
369 ms |
42360 KB |
Output is correct |
24 |
Correct |
258 ms |
41464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12672 KB |
Output is correct |
2 |
Correct |
15 ms |
12672 KB |
Output is correct |
3 |
Correct |
14 ms |
12672 KB |
Output is correct |
4 |
Correct |
15 ms |
12736 KB |
Output is correct |
5 |
Correct |
15 ms |
12644 KB |
Output is correct |
6 |
Correct |
13 ms |
12664 KB |
Output is correct |
7 |
Correct |
30 ms |
13540 KB |
Output is correct |
8 |
Correct |
25 ms |
13568 KB |
Output is correct |
9 |
Correct |
26 ms |
13568 KB |
Output is correct |
10 |
Correct |
23 ms |
13440 KB |
Output is correct |
11 |
Correct |
24 ms |
13440 KB |
Output is correct |
12 |
Correct |
19 ms |
13440 KB |
Output is correct |
13 |
Correct |
24 ms |
13568 KB |
Output is correct |
14 |
Correct |
26 ms |
13532 KB |
Output is correct |
15 |
Correct |
29 ms |
13440 KB |
Output is correct |
16 |
Correct |
22 ms |
13440 KB |
Output is correct |
17 |
Correct |
24 ms |
13436 KB |
Output is correct |
18 |
Correct |
18 ms |
13440 KB |
Output is correct |
19 |
Correct |
923 ms |
43256 KB |
Output is correct |
20 |
Correct |
1075 ms |
43280 KB |
Output is correct |
21 |
Correct |
990 ms |
43356 KB |
Output is correct |
22 |
Correct |
559 ms |
42692 KB |
Output is correct |
23 |
Correct |
800 ms |
42616 KB |
Output is correct |
24 |
Correct |
565 ms |
41832 KB |
Output is correct |
25 |
Correct |
905 ms |
43284 KB |
Output is correct |
26 |
Correct |
902 ms |
43344 KB |
Output is correct |
27 |
Correct |
781 ms |
43128 KB |
Output is correct |
28 |
Correct |
713 ms |
42492 KB |
Output is correct |
29 |
Correct |
433 ms |
42340 KB |
Output is correct |
30 |
Correct |
266 ms |
41440 KB |
Output is correct |
31 |
Correct |
924 ms |
43736 KB |
Output is correct |
32 |
Correct |
929 ms |
43800 KB |
Output is correct |
33 |
Correct |
935 ms |
43388 KB |
Output is correct |
34 |
Correct |
605 ms |
42852 KB |
Output is correct |
35 |
Correct |
851 ms |
42920 KB |
Output is correct |
36 |
Correct |
548 ms |
41848 KB |
Output is correct |
37 |
Correct |
1006 ms |
43840 KB |
Output is correct |
38 |
Correct |
1020 ms |
43664 KB |
Output is correct |
39 |
Correct |
985 ms |
43896 KB |
Output is correct |
40 |
Correct |
680 ms |
42360 KB |
Output is correct |
41 |
Correct |
369 ms |
42360 KB |
Output is correct |
42 |
Correct |
258 ms |
41464 KB |
Output is correct |
43 |
Correct |
1131 ms |
45672 KB |
Output is correct |
44 |
Correct |
1156 ms |
45688 KB |
Output is correct |
45 |
Correct |
1074 ms |
45768 KB |
Output is correct |
46 |
Correct |
684 ms |
44164 KB |
Output is correct |
47 |
Correct |
846 ms |
44148 KB |
Output is correct |
48 |
Correct |
466 ms |
41592 KB |
Output is correct |
49 |
Correct |
1049 ms |
45688 KB |
Output is correct |
50 |
Correct |
1088 ms |
45536 KB |
Output is correct |
51 |
Correct |
907 ms |
45496 KB |
Output is correct |
52 |
Correct |
769 ms |
43852 KB |
Output is correct |
53 |
Correct |
439 ms |
43260 KB |
Output is correct |