#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
void solve() {
ll n; cin>>n;
ll Q; cin>>Q;
map<ll, pair<ll, ll>> ord;
vector<pair<ll, pair<ll, ll>>> v;
for(ll i=1; i<=n; i++) {
ll l,r; cin>>l>>r;
v.push_back({r, {l, i}});
}
sort(v.begin(), v.end());
ll p=1, chain=1;
ll lst=-1;
for(auto [r, to]: v) {
ll l=to.f, i=to.s;
// cout<<i<<" ";
if(lst == -1 || l <= lst) {
ord[i]={chain, p++};
lst=r;
} else {
p=1;
ord[i]={++chain, p++};
lst=r;
}
}
// cout<<"\n\n";
// for(auto to: ord) {
// cout<<to.f<<" "<<to.s.f<<" "<<to.s.s<<"\n";
// }
for(ll i=1; i<=Q; i++) {
ll l, r; cin>>l>>r;
if(ord[r].f != ord[l].f || ord[l].s > ord[r].s) cout<<"impossible\n";
else cout<<ord[r].s-ord[l].s<<"\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
cout<<'\n';
}
}
/*
5 5
2 3
1 2
7 9
4 7
4 6
2 1
5 2
5 4
4 5
5 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
12604 KB |
Output is correct |
2 |
Correct |
153 ms |
12664 KB |
Output is correct |
3 |
Correct |
157 ms |
12736 KB |
Output is correct |
4 |
Correct |
100 ms |
13208 KB |
Output is correct |
5 |
Correct |
134 ms |
12984 KB |
Output is correct |
6 |
Incorrect |
136 ms |
12920 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |