/*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;
int n, q, b, e, jump[18][100000], tail = 0, mind, maxd, midd, curr;
pair<int64_t, int64_t> ranges[100000];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> ranges[i].first >> ranges[i].second;
sort(ranges, ranges + n);
for (int i = 0; i < n; i++){
while (ranges[tail].second < ranges[i].first){
jump[0][tail] = i - 1;
tail++;
}
}
for (; tail < n; tail++) jump[0][tail] = n - 1;
for (int i = 1; i < 18; i++) for (int j = 0; j < n; j++) jump[i][j] = jump[i - 1][jump[i - 1][j]];
while (q--){
cin >> b >> e;
if (b > e || jump[17][b] < e){
cout << "impossible\n";
continue;
}
mind = 0;
maxd = n - 1;
while (mind != maxd){
midd = (mind + maxd) / 2;
curr = b;
for (int i = 0; i < 18; i++) if ((midd >> i) % 2 == 1) curr = jump[i][curr];
if (curr >= e) maxd = midd;
else mind = midd + 1;
}
cout << mind << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
12496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |