/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
pair<int, pair<int, int>> endpoints[400000], curr;
int maxend[200000], pow2maxend[18][200000];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, p, q, ql, qr, qans, qskip;
cin >> n;
for (int i = 0; i < n; i++){
cin >> p;
endpoints[2 * i] = {p, {0, i}};
cin >> p;
endpoints[2 * i + 1] = {p, {1, i}};
maxend[i] = n - 1;
}
sort(endpoints, endpoints + 2 * n);
set<int> currranges, negcurrranges;
for (int i = 0; i < 2 * n; i++){
curr = endpoints[i];
if (curr.second.first == 1){
currranges.erase(curr.second.second);
negcurrranges.erase(-curr.second.second);
continue;
}
if (currranges.upper_bound(curr.second.second) != currranges.end()) maxend[curr.second.second] = min(maxend[curr.second.second], *currranges.upper_bound(curr.second.second) - 1);
if (negcurrranges.upper_bound(-curr.second.second) != negcurrranges.end()) maxend[-(*negcurrranges.upper_bound(-curr.second.second))] = min(maxend[-(*negcurrranges.upper_bound(-curr.second.second))], curr.second.second - 1);
currranges.insert(curr.second.second);
negcurrranges.insert(-curr.second.second);
}
pow2maxend[0][n - 1] = n - 1;
for (int i = n - 2; i >= 0; i--){
maxend[i] = min(maxend[i], maxend[i + 1]);
pow2maxend[0][i] = maxend[i];
}
for (int i = 1; i < 18; i++) for (int j = 0; j < n; j++) pow2maxend[i][j] = pow2maxend[i - 1][min(pow2maxend[i - 1][j] + 1, n - 1)];
cin >> q;
while (q--){
cin >> ql >> qr;
ql--;
qr--;
qans = 0;
while (ql <= qr){
for (qskip = 0; qskip < 17 && pow2maxend[qskip + 1][ql] < qr; qskip++);
qans += 1 << qskip;
ql = pow2maxend[qskip][ql] + 1;
}
cout << qans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
32456 KB |
Output is correct |
2 |
Correct |
292 ms |
32140 KB |
Output is correct |
3 |
Correct |
290 ms |
32080 KB |
Output is correct |
4 |
Correct |
290 ms |
32264 KB |
Output is correct |
5 |
Correct |
304 ms |
33056 KB |
Output is correct |
6 |
Correct |
189 ms |
39944 KB |
Output is correct |
7 |
Correct |
181 ms |
31808 KB |
Output is correct |
8 |
Correct |
180 ms |
28872 KB |
Output is correct |
9 |
Correct |
174 ms |
26964 KB |
Output is correct |
10 |
Correct |
154 ms |
24636 KB |
Output is correct |
11 |
Correct |
70 ms |
22936 KB |
Output is correct |
12 |
Correct |
66 ms |
22460 KB |
Output is correct |
13 |
Correct |
65 ms |
22608 KB |
Output is correct |
14 |
Correct |
71 ms |
22936 KB |
Output is correct |
15 |
Correct |
76 ms |
22864 KB |
Output is correct |
16 |
Correct |
2 ms |
16732 KB |
Output is correct |
17 |
Correct |
214 ms |
41576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
17240 KB |
Output is correct |
2 |
Correct |
8 ms |
17244 KB |
Output is correct |
3 |
Correct |
9 ms |
17244 KB |
Output is correct |
4 |
Correct |
8 ms |
17244 KB |
Output is correct |
5 |
Correct |
10 ms |
17264 KB |
Output is correct |
6 |
Correct |
6 ms |
17496 KB |
Output is correct |
7 |
Correct |
6 ms |
17276 KB |
Output is correct |
8 |
Correct |
6 ms |
16988 KB |
Output is correct |
9 |
Correct |
6 ms |
16968 KB |
Output is correct |
10 |
Correct |
6 ms |
16988 KB |
Output is correct |
11 |
Correct |
5 ms |
16984 KB |
Output is correct |
12 |
Correct |
4 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16988 KB |
Output is correct |
14 |
Correct |
5 ms |
16988 KB |
Output is correct |
15 |
Correct |
5 ms |
16988 KB |
Output is correct |
16 |
Correct |
2 ms |
16732 KB |
Output is correct |
17 |
Correct |
7 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
17240 KB |
Output is correct |
2 |
Correct |
8 ms |
17244 KB |
Output is correct |
3 |
Correct |
9 ms |
17244 KB |
Output is correct |
4 |
Correct |
8 ms |
17244 KB |
Output is correct |
5 |
Correct |
10 ms |
17264 KB |
Output is correct |
6 |
Correct |
6 ms |
17496 KB |
Output is correct |
7 |
Correct |
6 ms |
17276 KB |
Output is correct |
8 |
Correct |
6 ms |
16988 KB |
Output is correct |
9 |
Correct |
6 ms |
16968 KB |
Output is correct |
10 |
Correct |
6 ms |
16988 KB |
Output is correct |
11 |
Correct |
5 ms |
16984 KB |
Output is correct |
12 |
Correct |
4 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16988 KB |
Output is correct |
14 |
Correct |
5 ms |
16988 KB |
Output is correct |
15 |
Correct |
5 ms |
16988 KB |
Output is correct |
16 |
Correct |
2 ms |
16732 KB |
Output is correct |
17 |
Correct |
7 ms |
17500 KB |
Output is correct |
18 |
Correct |
56 ms |
19908 KB |
Output is correct |
19 |
Correct |
51 ms |
19524 KB |
Output is correct |
20 |
Correct |
55 ms |
19792 KB |
Output is correct |
21 |
Correct |
54 ms |
19536 KB |
Output is correct |
22 |
Correct |
53 ms |
19796 KB |
Output is correct |
23 |
Correct |
50 ms |
19696 KB |
Output is correct |
24 |
Correct |
53 ms |
20008 KB |
Output is correct |
25 |
Correct |
53 ms |
19792 KB |
Output is correct |
26 |
Correct |
49 ms |
19544 KB |
Output is correct |
27 |
Correct |
47 ms |
19420 KB |
Output is correct |
28 |
Correct |
34 ms |
19024 KB |
Output is correct |
29 |
Correct |
40 ms |
18972 KB |
Output is correct |
30 |
Correct |
35 ms |
19028 KB |
Output is correct |
31 |
Correct |
36 ms |
19028 KB |
Output is correct |
32 |
Correct |
35 ms |
19036 KB |
Output is correct |
33 |
Correct |
2 ms |
16728 KB |
Output is correct |
34 |
Correct |
57 ms |
19748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
33080 KB |
Output is correct |
2 |
Correct |
326 ms |
32756 KB |
Output is correct |
3 |
Correct |
269 ms |
31496 KB |
Output is correct |
4 |
Correct |
279 ms |
31340 KB |
Output is correct |
5 |
Correct |
282 ms |
31828 KB |
Output is correct |
6 |
Correct |
193 ms |
40132 KB |
Output is correct |
7 |
Correct |
178 ms |
31552 KB |
Output is correct |
8 |
Correct |
171 ms |
28608 KB |
Output is correct |
9 |
Correct |
163 ms |
26452 KB |
Output is correct |
10 |
Correct |
164 ms |
25424 KB |
Output is correct |
11 |
Correct |
66 ms |
22376 KB |
Output is correct |
12 |
Correct |
76 ms |
23124 KB |
Output is correct |
13 |
Correct |
66 ms |
22356 KB |
Output is correct |
14 |
Correct |
70 ms |
22612 KB |
Output is correct |
15 |
Correct |
73 ms |
23312 KB |
Output is correct |
16 |
Correct |
5 ms |
16728 KB |
Output is correct |
17 |
Correct |
189 ms |
40532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
32456 KB |
Output is correct |
2 |
Correct |
292 ms |
32140 KB |
Output is correct |
3 |
Correct |
290 ms |
32080 KB |
Output is correct |
4 |
Correct |
290 ms |
32264 KB |
Output is correct |
5 |
Correct |
304 ms |
33056 KB |
Output is correct |
6 |
Correct |
189 ms |
39944 KB |
Output is correct |
7 |
Correct |
181 ms |
31808 KB |
Output is correct |
8 |
Correct |
180 ms |
28872 KB |
Output is correct |
9 |
Correct |
174 ms |
26964 KB |
Output is correct |
10 |
Correct |
154 ms |
24636 KB |
Output is correct |
11 |
Correct |
70 ms |
22936 KB |
Output is correct |
12 |
Correct |
66 ms |
22460 KB |
Output is correct |
13 |
Correct |
65 ms |
22608 KB |
Output is correct |
14 |
Correct |
71 ms |
22936 KB |
Output is correct |
15 |
Correct |
76 ms |
22864 KB |
Output is correct |
16 |
Correct |
2 ms |
16732 KB |
Output is correct |
17 |
Correct |
214 ms |
41576 KB |
Output is correct |
18 |
Correct |
8 ms |
17240 KB |
Output is correct |
19 |
Correct |
8 ms |
17244 KB |
Output is correct |
20 |
Correct |
9 ms |
17244 KB |
Output is correct |
21 |
Correct |
8 ms |
17244 KB |
Output is correct |
22 |
Correct |
10 ms |
17264 KB |
Output is correct |
23 |
Correct |
6 ms |
17496 KB |
Output is correct |
24 |
Correct |
6 ms |
17276 KB |
Output is correct |
25 |
Correct |
6 ms |
16988 KB |
Output is correct |
26 |
Correct |
6 ms |
16968 KB |
Output is correct |
27 |
Correct |
6 ms |
16988 KB |
Output is correct |
28 |
Correct |
5 ms |
16984 KB |
Output is correct |
29 |
Correct |
4 ms |
16988 KB |
Output is correct |
30 |
Correct |
4 ms |
16988 KB |
Output is correct |
31 |
Correct |
5 ms |
16988 KB |
Output is correct |
32 |
Correct |
5 ms |
16988 KB |
Output is correct |
33 |
Correct |
2 ms |
16732 KB |
Output is correct |
34 |
Correct |
7 ms |
17500 KB |
Output is correct |
35 |
Correct |
56 ms |
19908 KB |
Output is correct |
36 |
Correct |
51 ms |
19524 KB |
Output is correct |
37 |
Correct |
55 ms |
19792 KB |
Output is correct |
38 |
Correct |
54 ms |
19536 KB |
Output is correct |
39 |
Correct |
53 ms |
19796 KB |
Output is correct |
40 |
Correct |
50 ms |
19696 KB |
Output is correct |
41 |
Correct |
53 ms |
20008 KB |
Output is correct |
42 |
Correct |
53 ms |
19792 KB |
Output is correct |
43 |
Correct |
49 ms |
19544 KB |
Output is correct |
44 |
Correct |
47 ms |
19420 KB |
Output is correct |
45 |
Correct |
34 ms |
19024 KB |
Output is correct |
46 |
Correct |
40 ms |
18972 KB |
Output is correct |
47 |
Correct |
35 ms |
19028 KB |
Output is correct |
48 |
Correct |
36 ms |
19028 KB |
Output is correct |
49 |
Correct |
35 ms |
19036 KB |
Output is correct |
50 |
Correct |
2 ms |
16728 KB |
Output is correct |
51 |
Correct |
57 ms |
19748 KB |
Output is correct |
52 |
Correct |
317 ms |
33080 KB |
Output is correct |
53 |
Correct |
326 ms |
32756 KB |
Output is correct |
54 |
Correct |
269 ms |
31496 KB |
Output is correct |
55 |
Correct |
279 ms |
31340 KB |
Output is correct |
56 |
Correct |
282 ms |
31828 KB |
Output is correct |
57 |
Correct |
193 ms |
40132 KB |
Output is correct |
58 |
Correct |
178 ms |
31552 KB |
Output is correct |
59 |
Correct |
171 ms |
28608 KB |
Output is correct |
60 |
Correct |
163 ms |
26452 KB |
Output is correct |
61 |
Correct |
164 ms |
25424 KB |
Output is correct |
62 |
Correct |
66 ms |
22376 KB |
Output is correct |
63 |
Correct |
76 ms |
23124 KB |
Output is correct |
64 |
Correct |
66 ms |
22356 KB |
Output is correct |
65 |
Correct |
70 ms |
22612 KB |
Output is correct |
66 |
Correct |
73 ms |
23312 KB |
Output is correct |
67 |
Correct |
5 ms |
16728 KB |
Output is correct |
68 |
Correct |
189 ms |
40532 KB |
Output is correct |
69 |
Correct |
431 ms |
35548 KB |
Output is correct |
70 |
Correct |
450 ms |
36436 KB |
Output is correct |
71 |
Correct |
380 ms |
35156 KB |
Output is correct |
72 |
Correct |
408 ms |
35652 KB |
Output is correct |
73 |
Correct |
399 ms |
35516 KB |
Output is correct |
74 |
Correct |
349 ms |
46148 KB |
Output is correct |
75 |
Correct |
283 ms |
35084 KB |
Output is correct |
76 |
Correct |
298 ms |
33464 KB |
Output is correct |
77 |
Correct |
279 ms |
29780 KB |
Output is correct |
78 |
Correct |
260 ms |
28376 KB |
Output is correct |
79 |
Correct |
120 ms |
26048 KB |
Output is correct |
80 |
Correct |
101 ms |
25184 KB |
Output is correct |
81 |
Correct |
121 ms |
25172 KB |
Output is correct |
82 |
Correct |
110 ms |
25972 KB |
Output is correct |
83 |
Correct |
103 ms |
25168 KB |
Output is correct |
84 |
Correct |
2 ms |
16732 KB |
Output is correct |
85 |
Correct |
257 ms |
43340 KB |
Output is correct |