#include<bits/stdc++.h>
using namespace std;
const int N = 200'000 + 50, K = 20;
int n, q, l[N], r[N], par[N][K];
set<pair<int, int> > st;
bool check(int l, int r)
{
if(st.empty()) return true;
auto it = st.upper_bound({r, 0});
if(it != st.end() && it->second <= r) return false;
if(it != st.begin())
{
it--;
if(l <= it->first) return false;
}
return true;
}
int main()
{
cin >> n;
for(int i = 0; i < n; i ++)
cin >> l[i] >> r[i];
int j = 0;
for(int i = 0; i < n; i ++)
{
while(j < n && check(l[j], r[j]))
st.insert({r[j], l[j]}), j++;
par[i][0] = j;
st.erase({r[i], l[i]});
}
for(int i = K - 1; i >= 0; i --) par[n][i] = n;
for(int i = n - 1; i >= 0; i --)
for(int l = 1; l < K; l++)
par[i][l] = par[par[i][l - 1]][l -1];
// cerr << par[0][0] << endl;
cin >> q;
while(q--)
{
int a, b;
cin >> a >> b;
a--;
int ans = 0;
for(int i = K - 1; i >= 0; i --)
if(par[a][i] < b) ans += (1 << i), a = par[a][i];
cout << ans + 1 << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
21072 KB |
Output is correct |
2 |
Correct |
118 ms |
21232 KB |
Output is correct |
3 |
Correct |
120 ms |
21076 KB |
Output is correct |
4 |
Correct |
114 ms |
21076 KB |
Output is correct |
5 |
Correct |
121 ms |
21428 KB |
Output is correct |
6 |
Correct |
121 ms |
20900 KB |
Output is correct |
7 |
Correct |
110 ms |
21060 KB |
Output is correct |
8 |
Correct |
145 ms |
20964 KB |
Output is correct |
9 |
Correct |
118 ms |
21168 KB |
Output is correct |
10 |
Correct |
118 ms |
20820 KB |
Output is correct |
11 |
Correct |
227 ms |
29844 KB |
Output is correct |
12 |
Correct |
212 ms |
29012 KB |
Output is correct |
13 |
Correct |
210 ms |
29012 KB |
Output is correct |
14 |
Correct |
223 ms |
25940 KB |
Output is correct |
15 |
Correct |
194 ms |
24600 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
107 ms |
21256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4852 KB |
Output is correct |
2 |
Correct |
10 ms |
4700 KB |
Output is correct |
3 |
Correct |
10 ms |
4700 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
10 ms |
4700 KB |
Output is correct |
6 |
Correct |
10 ms |
4876 KB |
Output is correct |
7 |
Correct |
10 ms |
4700 KB |
Output is correct |
8 |
Correct |
10 ms |
4700 KB |
Output is correct |
9 |
Correct |
11 ms |
4700 KB |
Output is correct |
10 |
Correct |
11 ms |
4700 KB |
Output is correct |
11 |
Correct |
10 ms |
4956 KB |
Output is correct |
12 |
Correct |
10 ms |
4956 KB |
Output is correct |
13 |
Correct |
10 ms |
5044 KB |
Output is correct |
14 |
Correct |
11 ms |
4700 KB |
Output is correct |
15 |
Correct |
10 ms |
4700 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
10 ms |
4868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4852 KB |
Output is correct |
2 |
Correct |
10 ms |
4700 KB |
Output is correct |
3 |
Correct |
10 ms |
4700 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
10 ms |
4700 KB |
Output is correct |
6 |
Correct |
10 ms |
4876 KB |
Output is correct |
7 |
Correct |
10 ms |
4700 KB |
Output is correct |
8 |
Correct |
10 ms |
4700 KB |
Output is correct |
9 |
Correct |
11 ms |
4700 KB |
Output is correct |
10 |
Correct |
11 ms |
4700 KB |
Output is correct |
11 |
Correct |
10 ms |
4956 KB |
Output is correct |
12 |
Correct |
10 ms |
4956 KB |
Output is correct |
13 |
Correct |
10 ms |
5044 KB |
Output is correct |
14 |
Correct |
11 ms |
4700 KB |
Output is correct |
15 |
Correct |
10 ms |
4700 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
10 ms |
4868 KB |
Output is correct |
18 |
Correct |
287 ms |
7508 KB |
Output is correct |
19 |
Correct |
272 ms |
7252 KB |
Output is correct |
20 |
Correct |
294 ms |
7536 KB |
Output is correct |
21 |
Correct |
267 ms |
7252 KB |
Output is correct |
22 |
Correct |
279 ms |
7252 KB |
Output is correct |
23 |
Correct |
267 ms |
7252 KB |
Output is correct |
24 |
Correct |
278 ms |
7400 KB |
Output is correct |
25 |
Correct |
280 ms |
7252 KB |
Output is correct |
26 |
Correct |
267 ms |
7256 KB |
Output is correct |
27 |
Correct |
250 ms |
7204 KB |
Output is correct |
28 |
Correct |
252 ms |
6868 KB |
Output is correct |
29 |
Correct |
260 ms |
7040 KB |
Output is correct |
30 |
Correct |
260 ms |
7128 KB |
Output is correct |
31 |
Correct |
261 ms |
6996 KB |
Output is correct |
32 |
Correct |
239 ms |
6996 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
269 ms |
7012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
21332 KB |
Output is correct |
2 |
Correct |
117 ms |
21332 KB |
Output is correct |
3 |
Correct |
116 ms |
21076 KB |
Output is correct |
4 |
Correct |
108 ms |
20820 KB |
Output is correct |
5 |
Correct |
112 ms |
21024 KB |
Output is correct |
6 |
Correct |
101 ms |
21076 KB |
Output is correct |
7 |
Correct |
107 ms |
20916 KB |
Output is correct |
8 |
Correct |
113 ms |
20820 KB |
Output is correct |
9 |
Correct |
110 ms |
20964 KB |
Output is correct |
10 |
Correct |
128 ms |
21312 KB |
Output is correct |
11 |
Correct |
204 ms |
29028 KB |
Output is correct |
12 |
Correct |
223 ms |
30292 KB |
Output is correct |
13 |
Correct |
201 ms |
28884 KB |
Output is correct |
14 |
Correct |
208 ms |
24916 KB |
Output is correct |
15 |
Correct |
233 ms |
25940 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
106 ms |
21120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
21072 KB |
Output is correct |
2 |
Correct |
118 ms |
21232 KB |
Output is correct |
3 |
Correct |
120 ms |
21076 KB |
Output is correct |
4 |
Correct |
114 ms |
21076 KB |
Output is correct |
5 |
Correct |
121 ms |
21428 KB |
Output is correct |
6 |
Correct |
121 ms |
20900 KB |
Output is correct |
7 |
Correct |
110 ms |
21060 KB |
Output is correct |
8 |
Correct |
145 ms |
20964 KB |
Output is correct |
9 |
Correct |
118 ms |
21168 KB |
Output is correct |
10 |
Correct |
118 ms |
20820 KB |
Output is correct |
11 |
Correct |
227 ms |
29844 KB |
Output is correct |
12 |
Correct |
212 ms |
29012 KB |
Output is correct |
13 |
Correct |
210 ms |
29012 KB |
Output is correct |
14 |
Correct |
223 ms |
25940 KB |
Output is correct |
15 |
Correct |
194 ms |
24600 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
107 ms |
21256 KB |
Output is correct |
18 |
Correct |
11 ms |
4852 KB |
Output is correct |
19 |
Correct |
10 ms |
4700 KB |
Output is correct |
20 |
Correct |
10 ms |
4700 KB |
Output is correct |
21 |
Correct |
10 ms |
4700 KB |
Output is correct |
22 |
Correct |
10 ms |
4700 KB |
Output is correct |
23 |
Correct |
10 ms |
4876 KB |
Output is correct |
24 |
Correct |
10 ms |
4700 KB |
Output is correct |
25 |
Correct |
10 ms |
4700 KB |
Output is correct |
26 |
Correct |
11 ms |
4700 KB |
Output is correct |
27 |
Correct |
11 ms |
4700 KB |
Output is correct |
28 |
Correct |
10 ms |
4956 KB |
Output is correct |
29 |
Correct |
10 ms |
4956 KB |
Output is correct |
30 |
Correct |
10 ms |
5044 KB |
Output is correct |
31 |
Correct |
11 ms |
4700 KB |
Output is correct |
32 |
Correct |
10 ms |
4700 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |
34 |
Correct |
10 ms |
4868 KB |
Output is correct |
35 |
Correct |
287 ms |
7508 KB |
Output is correct |
36 |
Correct |
272 ms |
7252 KB |
Output is correct |
37 |
Correct |
294 ms |
7536 KB |
Output is correct |
38 |
Correct |
267 ms |
7252 KB |
Output is correct |
39 |
Correct |
279 ms |
7252 KB |
Output is correct |
40 |
Correct |
267 ms |
7252 KB |
Output is correct |
41 |
Correct |
278 ms |
7400 KB |
Output is correct |
42 |
Correct |
280 ms |
7252 KB |
Output is correct |
43 |
Correct |
267 ms |
7256 KB |
Output is correct |
44 |
Correct |
250 ms |
7204 KB |
Output is correct |
45 |
Correct |
252 ms |
6868 KB |
Output is correct |
46 |
Correct |
260 ms |
7040 KB |
Output is correct |
47 |
Correct |
260 ms |
7128 KB |
Output is correct |
48 |
Correct |
261 ms |
6996 KB |
Output is correct |
49 |
Correct |
239 ms |
6996 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
269 ms |
7012 KB |
Output is correct |
52 |
Correct |
125 ms |
21332 KB |
Output is correct |
53 |
Correct |
117 ms |
21332 KB |
Output is correct |
54 |
Correct |
116 ms |
21076 KB |
Output is correct |
55 |
Correct |
108 ms |
20820 KB |
Output is correct |
56 |
Correct |
112 ms |
21024 KB |
Output is correct |
57 |
Correct |
101 ms |
21076 KB |
Output is correct |
58 |
Correct |
107 ms |
20916 KB |
Output is correct |
59 |
Correct |
113 ms |
20820 KB |
Output is correct |
60 |
Correct |
110 ms |
20964 KB |
Output is correct |
61 |
Correct |
128 ms |
21312 KB |
Output is correct |
62 |
Correct |
204 ms |
29028 KB |
Output is correct |
63 |
Correct |
223 ms |
30292 KB |
Output is correct |
64 |
Correct |
201 ms |
28884 KB |
Output is correct |
65 |
Correct |
208 ms |
24916 KB |
Output is correct |
66 |
Correct |
233 ms |
25940 KB |
Output is correct |
67 |
Correct |
0 ms |
2396 KB |
Output is correct |
68 |
Correct |
106 ms |
21120 KB |
Output is correct |
69 |
Correct |
467 ms |
24508 KB |
Output is correct |
70 |
Correct |
460 ms |
24688 KB |
Output is correct |
71 |
Correct |
523 ms |
24300 KB |
Output is correct |
72 |
Correct |
488 ms |
24612 KB |
Output is correct |
73 |
Correct |
416 ms |
24660 KB |
Output is correct |
74 |
Correct |
437 ms |
24916 KB |
Output is correct |
75 |
Correct |
412 ms |
24608 KB |
Output is correct |
76 |
Correct |
429 ms |
24920 KB |
Output is correct |
77 |
Correct |
422 ms |
24404 KB |
Output is correct |
78 |
Correct |
423 ms |
24660 KB |
Output is correct |
79 |
Correct |
500 ms |
33212 KB |
Output is correct |
80 |
Correct |
505 ms |
31696 KB |
Output is correct |
81 |
Correct |
499 ms |
31832 KB |
Output is correct |
82 |
Correct |
481 ms |
27732 KB |
Output is correct |
83 |
Correct |
483 ms |
27220 KB |
Output is correct |
84 |
Correct |
1 ms |
2396 KB |
Output is correct |
85 |
Correct |
385 ms |
24580 KB |
Output is correct |