#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, 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;
ll lst=-1;
for(auto [r, to]: v) {
ll l=to.f, i=to.s;
if(lst == -1 || (l <= lst && lst <= r)) {
ord[p++]=i;
lst=r;
}
}
for(ll i=1; i<=Q; i++) {
ll l, r; cin>>l>>r;
if(ord[r]-ord[l] < 0) cout<<"impossible\n";
else cout<<ord[r]-ord[l]<<"\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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
94 ms |
12468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |