// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 2e5 + 10;
vector<int> vec[N], F[N], comp = {(int) -1e9};
pii A[N]; int n, q, R[N], id[N], X[N], Y[N], Z[N];
void init(int x, int y) {
for (; x < N; x += x & -x) {
vec[x].push_back(y);
}
}
void upd(int r, int _c) {
for (; r < N; r += r & -r) {
int c = lower_bound(vec[r].begin(), vec[r].end(), _c) - vec[r].begin();
for (; c < SZ(F[r]); c += c & -c) F[r][c]++;
}
}
int get(int r, int _c) {
int ret = 0;
for (; r; r -= r & -r) {
int c = upper_bound(vec[r].begin(), vec[r].end(), _c) - vec[r].begin() - 1;
for (; c; c -= c & -c) ret += F[r][c];
}
return ret;
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) scanf("%d%d", &A[i].F, &A[i].S), comp.push_back(-A[i].F);
sort(A + 1, A + n + 1, [&] (pii a, pii b) { return a.F + a.S > b.F + b.S; });
for (int i = 1; i <= q; i++) {
scanf("%d%d%d", &X[i], &Y[i], &Z[i]); id[i] = i;
comp.push_back(-X[i]);
}
sort(comp.begin(), comp.end());
comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
sort(id + 1, id + q + 1, [&] (int i, int j) { return Z[i] > Z[j]; });
for (int i = 1; i <= n; i++) {
init(lower_bound(comp.begin(), comp.end(), -A[i].F) - comp.begin(), -A[i].S);
}
for (int i = 0; i < N; i++) {
vec[i].push_back(-1e9); vec[i].push_back(0);
sort(vec[i].begin(), vec[i].end());
vec[i].resize(unique(vec[i].begin(), vec[i].end()) - vec[i].begin());
while (SZ(F[i]) < SZ(vec[i]) + 5) F[i].push_back(0);
}
int ptr = 1;
for (int _ = 1; _ <= q; _++) {
int i = id[_];
while (ptr <= n && A[ptr].F + A[ptr].S >= Z[i]) {
upd(lower_bound(comp.begin(), comp.end(), -A[ptr].F) - comp.begin(), -A[ptr].S);
ptr++;
}
R[i] = get(lower_bound(comp.begin(), comp.end(), -X[i]) - comp.begin(), -Y[i]);
}
for (int i = 1; i <= q; i++) printf("%d\n", R[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
40 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:41:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
41 | for (int i = 1; i <= n; i++) scanf("%d%d", &A[i].F, &A[i].S), comp.push_back(-A[i].F);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
44 | scanf("%d%d%d", &X[i], &Y[i], &Z[i]); id[i] = i;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
25452 KB |
Output is correct |
2 |
Correct |
68 ms |
25452 KB |
Output is correct |
3 |
Correct |
68 ms |
25452 KB |
Output is correct |
4 |
Correct |
72 ms |
25468 KB |
Output is correct |
5 |
Correct |
68 ms |
25452 KB |
Output is correct |
6 |
Correct |
69 ms |
25372 KB |
Output is correct |
7 |
Correct |
84 ms |
25836 KB |
Output is correct |
8 |
Correct |
84 ms |
25836 KB |
Output is correct |
9 |
Correct |
83 ms |
25836 KB |
Output is correct |
10 |
Correct |
79 ms |
25836 KB |
Output is correct |
11 |
Correct |
80 ms |
26092 KB |
Output is correct |
12 |
Correct |
77 ms |
25836 KB |
Output is correct |
13 |
Correct |
91 ms |
25836 KB |
Output is correct |
14 |
Correct |
83 ms |
25836 KB |
Output is correct |
15 |
Correct |
83 ms |
25836 KB |
Output is correct |
16 |
Correct |
79 ms |
26092 KB |
Output is correct |
17 |
Correct |
78 ms |
25708 KB |
Output is correct |
18 |
Correct |
79 ms |
25836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
596 ms |
39776 KB |
Output is correct |
2 |
Correct |
592 ms |
39776 KB |
Output is correct |
3 |
Correct |
601 ms |
39860 KB |
Output is correct |
4 |
Correct |
311 ms |
35936 KB |
Output is correct |
5 |
Correct |
355 ms |
41824 KB |
Output is correct |
6 |
Correct |
226 ms |
36960 KB |
Output is correct |
7 |
Correct |
540 ms |
38780 KB |
Output is correct |
8 |
Correct |
563 ms |
39896 KB |
Output is correct |
9 |
Correct |
516 ms |
38880 KB |
Output is correct |
10 |
Correct |
321 ms |
41232 KB |
Output is correct |
11 |
Correct |
250 ms |
34144 KB |
Output is correct |
12 |
Correct |
188 ms |
36448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
596 ms |
39776 KB |
Output is correct |
2 |
Correct |
592 ms |
39776 KB |
Output is correct |
3 |
Correct |
601 ms |
39860 KB |
Output is correct |
4 |
Correct |
311 ms |
35936 KB |
Output is correct |
5 |
Correct |
355 ms |
41824 KB |
Output is correct |
6 |
Correct |
226 ms |
36960 KB |
Output is correct |
7 |
Correct |
540 ms |
38780 KB |
Output is correct |
8 |
Correct |
563 ms |
39896 KB |
Output is correct |
9 |
Correct |
516 ms |
38880 KB |
Output is correct |
10 |
Correct |
321 ms |
41232 KB |
Output is correct |
11 |
Correct |
250 ms |
34144 KB |
Output is correct |
12 |
Correct |
188 ms |
36448 KB |
Output is correct |
13 |
Correct |
647 ms |
39776 KB |
Output is correct |
14 |
Correct |
639 ms |
39800 KB |
Output is correct |
15 |
Correct |
592 ms |
39776 KB |
Output is correct |
16 |
Correct |
344 ms |
35936 KB |
Output is correct |
17 |
Correct |
381 ms |
41952 KB |
Output is correct |
18 |
Correct |
230 ms |
37088 KB |
Output is correct |
19 |
Correct |
642 ms |
39776 KB |
Output is correct |
20 |
Correct |
648 ms |
39772 KB |
Output is correct |
21 |
Correct |
621 ms |
39392 KB |
Output is correct |
22 |
Correct |
366 ms |
41312 KB |
Output is correct |
23 |
Correct |
275 ms |
34192 KB |
Output is correct |
24 |
Correct |
182 ms |
36340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
25452 KB |
Output is correct |
2 |
Correct |
68 ms |
25452 KB |
Output is correct |
3 |
Correct |
68 ms |
25452 KB |
Output is correct |
4 |
Correct |
72 ms |
25468 KB |
Output is correct |
5 |
Correct |
68 ms |
25452 KB |
Output is correct |
6 |
Correct |
69 ms |
25372 KB |
Output is correct |
7 |
Correct |
84 ms |
25836 KB |
Output is correct |
8 |
Correct |
84 ms |
25836 KB |
Output is correct |
9 |
Correct |
83 ms |
25836 KB |
Output is correct |
10 |
Correct |
79 ms |
25836 KB |
Output is correct |
11 |
Correct |
80 ms |
26092 KB |
Output is correct |
12 |
Correct |
77 ms |
25836 KB |
Output is correct |
13 |
Correct |
91 ms |
25836 KB |
Output is correct |
14 |
Correct |
83 ms |
25836 KB |
Output is correct |
15 |
Correct |
83 ms |
25836 KB |
Output is correct |
16 |
Correct |
79 ms |
26092 KB |
Output is correct |
17 |
Correct |
78 ms |
25708 KB |
Output is correct |
18 |
Correct |
79 ms |
25836 KB |
Output is correct |
19 |
Correct |
596 ms |
39776 KB |
Output is correct |
20 |
Correct |
592 ms |
39776 KB |
Output is correct |
21 |
Correct |
601 ms |
39860 KB |
Output is correct |
22 |
Correct |
311 ms |
35936 KB |
Output is correct |
23 |
Correct |
355 ms |
41824 KB |
Output is correct |
24 |
Correct |
226 ms |
36960 KB |
Output is correct |
25 |
Correct |
540 ms |
38780 KB |
Output is correct |
26 |
Correct |
563 ms |
39896 KB |
Output is correct |
27 |
Correct |
516 ms |
38880 KB |
Output is correct |
28 |
Correct |
321 ms |
41232 KB |
Output is correct |
29 |
Correct |
250 ms |
34144 KB |
Output is correct |
30 |
Correct |
188 ms |
36448 KB |
Output is correct |
31 |
Correct |
647 ms |
39776 KB |
Output is correct |
32 |
Correct |
639 ms |
39800 KB |
Output is correct |
33 |
Correct |
592 ms |
39776 KB |
Output is correct |
34 |
Correct |
344 ms |
35936 KB |
Output is correct |
35 |
Correct |
381 ms |
41952 KB |
Output is correct |
36 |
Correct |
230 ms |
37088 KB |
Output is correct |
37 |
Correct |
642 ms |
39776 KB |
Output is correct |
38 |
Correct |
648 ms |
39772 KB |
Output is correct |
39 |
Correct |
621 ms |
39392 KB |
Output is correct |
40 |
Correct |
366 ms |
41312 KB |
Output is correct |
41 |
Correct |
275 ms |
34192 KB |
Output is correct |
42 |
Correct |
182 ms |
36340 KB |
Output is correct |
43 |
Correct |
690 ms |
38880 KB |
Output is correct |
44 |
Correct |
701 ms |
43688 KB |
Output is correct |
45 |
Correct |
678 ms |
43616 KB |
Output is correct |
46 |
Correct |
374 ms |
38692 KB |
Output is correct |
47 |
Correct |
394 ms |
47356 KB |
Output is correct |
48 |
Correct |
234 ms |
38112 KB |
Output is correct |
49 |
Correct |
634 ms |
44896 KB |
Output is correct |
50 |
Correct |
667 ms |
43700 KB |
Output is correct |
51 |
Correct |
612 ms |
45024 KB |
Output is correct |
52 |
Correct |
369 ms |
47072 KB |
Output is correct |
53 |
Correct |
290 ms |
35964 KB |
Output is correct |