#include <bits/stdc++.h>
using namespace std;
int N,Q, p[200005][20];
pair<int,int> lst[200005];
set< pair<int,int> > s;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N;
for (int i = 0; i < N; ++i) cin >> lst[i].first >> lst[i].second;
memset(p,-1,sizeof(p));
for (int l = 0, r = 0; l < N; ++l) {
while (r < N) {
bool can = true;
auto it = s.lower_bound(make_pair(lst[r].first,-1));
if (it != s.end() && it->first <= lst[r].second) can = false;
if (it != s.begin() && prev(it)->second >= lst[r].first) can = false;
if (!can) break;
s.insert(lst[r++]);
}
p[l][0] = r;
s.erase(lst[l]);
}
for (int k = 1; k < 20; ++k) for (int i = 0; i < N; ++i) {
if (p[i][k-1] == -1) p[i][k] = -1;
else p[i][k] = p[p[i][k-1]][k-1];
}
cin >> Q;
while (Q--) {
int l,r; cin >> l >> r; l--, r--;
int ans = 1;
for (int k = 19; k >= 0; --k) if (p[l][k] != -1 && p[l][k] <= r) ans += (1<<k), l = p[l][k];
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
17860 KB |
Output is correct |
2 |
Correct |
80 ms |
17824 KB |
Output is correct |
3 |
Correct |
85 ms |
17888 KB |
Output is correct |
4 |
Correct |
141 ms |
18028 KB |
Output is correct |
5 |
Correct |
87 ms |
18148 KB |
Output is correct |
6 |
Correct |
71 ms |
18112 KB |
Output is correct |
7 |
Correct |
86 ms |
18080 KB |
Output is correct |
8 |
Correct |
92 ms |
18092 KB |
Output is correct |
9 |
Correct |
91 ms |
18212 KB |
Output is correct |
10 |
Correct |
120 ms |
18160 KB |
Output is correct |
11 |
Correct |
249 ms |
27428 KB |
Output is correct |
12 |
Correct |
251 ms |
26764 KB |
Output is correct |
13 |
Correct |
252 ms |
26700 KB |
Output is correct |
14 |
Correct |
210 ms |
23468 KB |
Output is correct |
15 |
Correct |
192 ms |
22132 KB |
Output is correct |
16 |
Correct |
7 ms |
15948 KB |
Output is correct |
17 |
Correct |
86 ms |
18232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16068 KB |
Output is correct |
2 |
Correct |
10 ms |
16172 KB |
Output is correct |
3 |
Correct |
10 ms |
16076 KB |
Output is correct |
4 |
Correct |
14 ms |
16076 KB |
Output is correct |
5 |
Correct |
10 ms |
16144 KB |
Output is correct |
6 |
Correct |
10 ms |
16112 KB |
Output is correct |
7 |
Correct |
10 ms |
16076 KB |
Output is correct |
8 |
Correct |
13 ms |
16076 KB |
Output is correct |
9 |
Correct |
14 ms |
16156 KB |
Output is correct |
10 |
Correct |
12 ms |
16164 KB |
Output is correct |
11 |
Correct |
11 ms |
16332 KB |
Output is correct |
12 |
Correct |
11 ms |
16280 KB |
Output is correct |
13 |
Correct |
10 ms |
16300 KB |
Output is correct |
14 |
Correct |
12 ms |
16156 KB |
Output is correct |
15 |
Correct |
12 ms |
16180 KB |
Output is correct |
16 |
Correct |
7 ms |
15936 KB |
Output is correct |
17 |
Correct |
10 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16068 KB |
Output is correct |
2 |
Correct |
10 ms |
16172 KB |
Output is correct |
3 |
Correct |
10 ms |
16076 KB |
Output is correct |
4 |
Correct |
14 ms |
16076 KB |
Output is correct |
5 |
Correct |
10 ms |
16144 KB |
Output is correct |
6 |
Correct |
10 ms |
16112 KB |
Output is correct |
7 |
Correct |
10 ms |
16076 KB |
Output is correct |
8 |
Correct |
13 ms |
16076 KB |
Output is correct |
9 |
Correct |
14 ms |
16156 KB |
Output is correct |
10 |
Correct |
12 ms |
16164 KB |
Output is correct |
11 |
Correct |
11 ms |
16332 KB |
Output is correct |
12 |
Correct |
11 ms |
16280 KB |
Output is correct |
13 |
Correct |
10 ms |
16300 KB |
Output is correct |
14 |
Correct |
12 ms |
16156 KB |
Output is correct |
15 |
Correct |
12 ms |
16180 KB |
Output is correct |
16 |
Correct |
7 ms |
15936 KB |
Output is correct |
17 |
Correct |
10 ms |
16076 KB |
Output is correct |
18 |
Correct |
76 ms |
18740 KB |
Output is correct |
19 |
Correct |
79 ms |
18508 KB |
Output is correct |
20 |
Correct |
73 ms |
18800 KB |
Output is correct |
21 |
Correct |
69 ms |
18496 KB |
Output is correct |
22 |
Correct |
86 ms |
18616 KB |
Output is correct |
23 |
Correct |
68 ms |
18608 KB |
Output is correct |
24 |
Correct |
70 ms |
18712 KB |
Output is correct |
25 |
Correct |
85 ms |
18792 KB |
Output is correct |
26 |
Correct |
89 ms |
18628 KB |
Output is correct |
27 |
Correct |
76 ms |
18492 KB |
Output is correct |
28 |
Correct |
69 ms |
18396 KB |
Output is correct |
29 |
Correct |
56 ms |
18448 KB |
Output is correct |
30 |
Correct |
55 ms |
18372 KB |
Output is correct |
31 |
Correct |
60 ms |
18288 KB |
Output is correct |
32 |
Correct |
55 ms |
18244 KB |
Output is correct |
33 |
Correct |
7 ms |
15924 KB |
Output is correct |
34 |
Correct |
62 ms |
18484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
18284 KB |
Output is correct |
2 |
Correct |
117 ms |
18252 KB |
Output is correct |
3 |
Correct |
89 ms |
18144 KB |
Output is correct |
4 |
Correct |
80 ms |
18076 KB |
Output is correct |
5 |
Correct |
81 ms |
18204 KB |
Output is correct |
6 |
Correct |
74 ms |
18036 KB |
Output is correct |
7 |
Correct |
78 ms |
18132 KB |
Output is correct |
8 |
Correct |
87 ms |
18068 KB |
Output is correct |
9 |
Correct |
116 ms |
18036 KB |
Output is correct |
10 |
Correct |
100 ms |
18252 KB |
Output is correct |
11 |
Correct |
196 ms |
26688 KB |
Output is correct |
12 |
Correct |
260 ms |
30188 KB |
Output is correct |
13 |
Correct |
203 ms |
28872 KB |
Output is correct |
14 |
Correct |
175 ms |
24772 KB |
Output is correct |
15 |
Correct |
196 ms |
25984 KB |
Output is correct |
16 |
Correct |
8 ms |
15928 KB |
Output is correct |
17 |
Correct |
76 ms |
21028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
17860 KB |
Output is correct |
2 |
Correct |
80 ms |
17824 KB |
Output is correct |
3 |
Correct |
85 ms |
17888 KB |
Output is correct |
4 |
Correct |
141 ms |
18028 KB |
Output is correct |
5 |
Correct |
87 ms |
18148 KB |
Output is correct |
6 |
Correct |
71 ms |
18112 KB |
Output is correct |
7 |
Correct |
86 ms |
18080 KB |
Output is correct |
8 |
Correct |
92 ms |
18092 KB |
Output is correct |
9 |
Correct |
91 ms |
18212 KB |
Output is correct |
10 |
Correct |
120 ms |
18160 KB |
Output is correct |
11 |
Correct |
249 ms |
27428 KB |
Output is correct |
12 |
Correct |
251 ms |
26764 KB |
Output is correct |
13 |
Correct |
252 ms |
26700 KB |
Output is correct |
14 |
Correct |
210 ms |
23468 KB |
Output is correct |
15 |
Correct |
192 ms |
22132 KB |
Output is correct |
16 |
Correct |
7 ms |
15948 KB |
Output is correct |
17 |
Correct |
86 ms |
18232 KB |
Output is correct |
18 |
Correct |
10 ms |
16068 KB |
Output is correct |
19 |
Correct |
10 ms |
16172 KB |
Output is correct |
20 |
Correct |
10 ms |
16076 KB |
Output is correct |
21 |
Correct |
14 ms |
16076 KB |
Output is correct |
22 |
Correct |
10 ms |
16144 KB |
Output is correct |
23 |
Correct |
10 ms |
16112 KB |
Output is correct |
24 |
Correct |
10 ms |
16076 KB |
Output is correct |
25 |
Correct |
13 ms |
16076 KB |
Output is correct |
26 |
Correct |
14 ms |
16156 KB |
Output is correct |
27 |
Correct |
12 ms |
16164 KB |
Output is correct |
28 |
Correct |
11 ms |
16332 KB |
Output is correct |
29 |
Correct |
11 ms |
16280 KB |
Output is correct |
30 |
Correct |
10 ms |
16300 KB |
Output is correct |
31 |
Correct |
12 ms |
16156 KB |
Output is correct |
32 |
Correct |
12 ms |
16180 KB |
Output is correct |
33 |
Correct |
7 ms |
15936 KB |
Output is correct |
34 |
Correct |
10 ms |
16076 KB |
Output is correct |
35 |
Correct |
76 ms |
18740 KB |
Output is correct |
36 |
Correct |
79 ms |
18508 KB |
Output is correct |
37 |
Correct |
73 ms |
18800 KB |
Output is correct |
38 |
Correct |
69 ms |
18496 KB |
Output is correct |
39 |
Correct |
86 ms |
18616 KB |
Output is correct |
40 |
Correct |
68 ms |
18608 KB |
Output is correct |
41 |
Correct |
70 ms |
18712 KB |
Output is correct |
42 |
Correct |
85 ms |
18792 KB |
Output is correct |
43 |
Correct |
89 ms |
18628 KB |
Output is correct |
44 |
Correct |
76 ms |
18492 KB |
Output is correct |
45 |
Correct |
69 ms |
18396 KB |
Output is correct |
46 |
Correct |
56 ms |
18448 KB |
Output is correct |
47 |
Correct |
55 ms |
18372 KB |
Output is correct |
48 |
Correct |
60 ms |
18288 KB |
Output is correct |
49 |
Correct |
55 ms |
18244 KB |
Output is correct |
50 |
Correct |
7 ms |
15924 KB |
Output is correct |
51 |
Correct |
62 ms |
18484 KB |
Output is correct |
52 |
Correct |
88 ms |
18284 KB |
Output is correct |
53 |
Correct |
117 ms |
18252 KB |
Output is correct |
54 |
Correct |
89 ms |
18144 KB |
Output is correct |
55 |
Correct |
80 ms |
18076 KB |
Output is correct |
56 |
Correct |
81 ms |
18204 KB |
Output is correct |
57 |
Correct |
74 ms |
18036 KB |
Output is correct |
58 |
Correct |
78 ms |
18132 KB |
Output is correct |
59 |
Correct |
87 ms |
18068 KB |
Output is correct |
60 |
Correct |
116 ms |
18036 KB |
Output is correct |
61 |
Correct |
100 ms |
18252 KB |
Output is correct |
62 |
Correct |
196 ms |
26688 KB |
Output is correct |
63 |
Correct |
260 ms |
30188 KB |
Output is correct |
64 |
Correct |
203 ms |
28872 KB |
Output is correct |
65 |
Correct |
175 ms |
24772 KB |
Output is correct |
66 |
Correct |
196 ms |
25984 KB |
Output is correct |
67 |
Correct |
8 ms |
15928 KB |
Output is correct |
68 |
Correct |
76 ms |
21028 KB |
Output is correct |
69 |
Correct |
275 ms |
24460 KB |
Output is correct |
70 |
Correct |
262 ms |
24780 KB |
Output is correct |
71 |
Correct |
248 ms |
24204 KB |
Output is correct |
72 |
Correct |
246 ms |
24524 KB |
Output is correct |
73 |
Correct |
245 ms |
24448 KB |
Output is correct |
74 |
Correct |
298 ms |
24944 KB |
Output is correct |
75 |
Correct |
274 ms |
24408 KB |
Output is correct |
76 |
Correct |
267 ms |
24848 KB |
Output is correct |
77 |
Correct |
258 ms |
24264 KB |
Output is correct |
78 |
Correct |
263 ms |
24516 KB |
Output is correct |
79 |
Correct |
311 ms |
32964 KB |
Output is correct |
80 |
Correct |
304 ms |
31672 KB |
Output is correct |
81 |
Correct |
267 ms |
31656 KB |
Output is correct |
82 |
Correct |
244 ms |
27564 KB |
Output is correct |
83 |
Correct |
234 ms |
27072 KB |
Output is correct |
84 |
Correct |
6 ms |
15940 KB |
Output is correct |
85 |
Correct |
177 ms |
24356 KB |
Output is correct |