/*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, dist[5000][5000], endloc[5000];
pair<int64_t, pair<bool, int>> endpoints[10000];
map<int64_t, int> currdists;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> q;
for (int i = 0; i < n; i++){
cin >> b >> e;
endpoints[2 * i] = {b, {0, i}};
endpoints[2 * i + 1] = {e, {1, i}};
for (int j = 0; j < n; j++) dist[i][j] = - (int) (i != j);
}
sort(endpoints, endpoints + 2 * n);
for (int i = 0; i < 2 * n; i++) if (endpoints[i].second.first) endloc[endpoints[i].second.second] = i;
for (int i = 0; i < n; i++){
currdists = {{0, 1}};
for (int j = endloc[i] - 1; j > -1; j--){
if (endpoints[j].second.first){
dist[endpoints[j].second.second][i] = 1 + (*currdists.begin()).first;
currdists[dist[endpoints[j].second.second][i]]++;
} else{
currdists[dist[endpoints[j].second.second][i]]--;
while (!currdists.empty() && (*currdists.begin()).second < 1) currdists.erase(currdists.begin());
if (currdists.empty()) break;
}
}
}
while (q--){
cin >> b >> e;
b--;
e--;
if (b == e) cout << "0\n";
else if (endpoints[endloc[e]].first == endpoints[endloc[b]].first) cout << "1\n";
else{
if (endpoints[endloc[e]].first < endpoints[endloc[b]].first) cout << "impossible\n";
else if (dist[b][e] > -1) cout << dist[b][e] << '\n';
else cout << "impossible\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
403 ms |
199080 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
23 ms |
21020 KB |
Output is correct |
4 |
Correct |
13 ms |
20828 KB |
Output is correct |
5 |
Correct |
24 ms |
21020 KB |
Output is correct |
6 |
Incorrect |
8 ms |
20828 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
23 ms |
21020 KB |
Output is correct |
4 |
Correct |
13 ms |
20828 KB |
Output is correct |
5 |
Correct |
24 ms |
21020 KB |
Output is correct |
6 |
Incorrect |
8 ms |
20828 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
23 ms |
21020 KB |
Output is correct |
4 |
Correct |
13 ms |
20828 KB |
Output is correct |
5 |
Correct |
24 ms |
21020 KB |
Output is correct |
6 |
Incorrect |
8 ms |
20828 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
421 ms |
199328 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
403 ms |
199080 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |