#include <bits/stdc++.h>
using namespace std;
int N, Q, INF = 2e9;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> Q;
array<int, 2> a[N], _;
vector<array<int, 2>> qAt[N];
for(auto &[r, h] : a)
cin >> r >> h, r = -r;
sort(a, a+N);
int res[Q] = {};
for(int i = 0; i < Q; ++i) {
int A, B; cin >> A >> B;
if(a[0][0] <= -A)
qAt[lower_bound(a, a+N, _={-A, INF}) - a - 1].push_back({B, i});
}
int L[N], *R = L;
for(int i = 0; i < N; ++i) {
int v = a[i][1];
if(!i || R[-1] <= v) *R++ = v;
else *upper_bound(L, R, v) = v;
for(auto &[w, qI] : qAt[i])
res[qI] = upper_bound(L, R, w) - L;
}
for(int &i : res) cout << i << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
248 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
248 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
248 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
440 KB |
Output is correct |
24 |
Correct |
2 ms |
452 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
420 KB |
Output is correct |
27 |
Correct |
3 ms |
432 KB |
Output is correct |
28 |
Correct |
2 ms |
452 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
396 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
440 KB |
Output is correct |
33 |
Correct |
2 ms |
452 KB |
Output is correct |
34 |
Correct |
2 ms |
436 KB |
Output is correct |
35 |
Correct |
2 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
248 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
440 KB |
Output is correct |
24 |
Correct |
2 ms |
452 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
420 KB |
Output is correct |
27 |
Correct |
3 ms |
432 KB |
Output is correct |
28 |
Correct |
2 ms |
452 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
396 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
440 KB |
Output is correct |
33 |
Correct |
2 ms |
452 KB |
Output is correct |
34 |
Correct |
2 ms |
436 KB |
Output is correct |
35 |
Correct |
2 ms |
452 KB |
Output is correct |
36 |
Correct |
187 ms |
17548 KB |
Output is correct |
37 |
Correct |
205 ms |
17056 KB |
Output is correct |
38 |
Correct |
71 ms |
7448 KB |
Output is correct |
39 |
Correct |
141 ms |
13936 KB |
Output is correct |
40 |
Correct |
134 ms |
14404 KB |
Output is correct |
41 |
Correct |
183 ms |
16916 KB |
Output is correct |
42 |
Correct |
103 ms |
12824 KB |
Output is correct |
43 |
Correct |
76 ms |
12716 KB |
Output is correct |
44 |
Correct |
220 ms |
20292 KB |
Output is correct |
45 |
Correct |
204 ms |
20364 KB |
Output is correct |
46 |
Correct |
207 ms |
20360 KB |
Output is correct |
47 |
Correct |
216 ms |
20060 KB |
Output is correct |
48 |
Correct |
185 ms |
20548 KB |
Output is correct |
49 |
Correct |
242 ms |
19980 KB |
Output is correct |
50 |
Correct |
190 ms |
20548 KB |
Output is correct |