#include "bits/stdc++.h"
using namespace std;
#define INF 2000000000
#define INFLL 3000000000000000000LL
#define ll long long
int main() {
cin.tie(0)->sync_with_stdio(0);
int n,q;
cin>>n>>q;
pair<pair<int,int>,int>arr[n];
for(int i=0;i<n;i++){
int l,r;
cin>>l>>r;
arr[i]={{l,r},i+1};
}
sort(arr,arr+n);
map<int,int>mp;
for(int i=0;i<n;i++){
mp[arr[i].second]=i;
}
set<int>s;
for(int i=1;i<n;i++){
if(arr[i-1].first.second<arr[i].first.first){
s.insert(i);
}
}
cout<<"\n";
while(q--){
int a,b;
cin>>a>>b;
auto it=s.upper_bound(a);
if(it!=s.end())if((*it)<=b){
cout<<"impossible\n";
continue;
}
int out=mp[b]-mp[a];
if(out<0)cout<<"impossible\n";
else cout<<out<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
6720 KB |
Output is correct |
2 |
Correct |
133 ms |
6720 KB |
Output is correct |
3 |
Correct |
152 ms |
6756 KB |
Output is correct |
4 |
Incorrect |
141 ms |
11716 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |