#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=100010;
int N, Q, S[Nmax], E[Nmax], p, I[Nmax], X[20][Nmax];
vector<pair<int, int>> V;
set<int> T;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>Q;
for(int i=1; i<=N; i++) {
cin>>S[i]>>E[i];
V.push_back({S[i], -i});
V.push_back({E[i], i});
}
sort(V.begin(), V.end());
for(auto [t, k]:V) {
if(k>0) {
T.erase(k), I[k]=++p;
if(!T.empty()) X[0][k]=(*T.begin());
}
else T.insert(-k);
}
for(int i=1; i<20; i++) for(int j=1; j<=N; j++) X[i][j]=X[i-1][X[i-1][j]];
while(Q--) {
int ans=0;
int s, e; cin>>s>>e;
for(int i=19; i>=0; i--) if(X[i][s] && I[X[i][s]]<=I[e]) s=X[i][s], ans+=(1<<i);
if(s==e) cout<<ans<<"\n";
else cout<<"impossible\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
57 ms |
26020 KB |
Output is correct |
3 |
Correct |
71 ms |
25788 KB |
Output is correct |
4 |
Correct |
83 ms |
25532 KB |
Output is correct |
5 |
Correct |
78 ms |
25280 KB |
Output is correct |
6 |
Correct |
72 ms |
25276 KB |
Output is correct |
7 |
Incorrect |
73 ms |
26048 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
25256 KB |
Output is correct |
2 |
Correct |
70 ms |
25536 KB |
Output is correct |
3 |
Correct |
79 ms |
25228 KB |
Output is correct |
4 |
Correct |
54 ms |
25532 KB |
Output is correct |
5 |
Correct |
76 ms |
26304 KB |
Output is correct |
6 |
Incorrect |
72 ms |
25768 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
57 ms |
26020 KB |
Output is correct |
3 |
Correct |
71 ms |
25788 KB |
Output is correct |
4 |
Correct |
83 ms |
25532 KB |
Output is correct |
5 |
Correct |
78 ms |
25280 KB |
Output is correct |
6 |
Correct |
72 ms |
25276 KB |
Output is correct |
7 |
Incorrect |
73 ms |
26048 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |