Submission #782038

#TimeUsernameProblemLanguageResultExecution timeMemory
782038VadimKEvent Hopping (BOI22_events)C++17
0 / 100
265 ms6056 KiB
#include <bits/stdc++.h> using namespace std; struct event { int s; int f; int num; }; bool cmp (event a, event b) { if (a.f==b.f) return a.s<=b.s; return a.f<b.f; } int main() { int n,q; cin>>n>>q; event arr[n+1]; int p[n+1]; for (int i=1; i<=n; i++) cin>>arr[i].s>>arr[i].f; for (int i=1; i<=n; i++) arr[i].num=i; sort (arr+1,arr+n+1,cmp); for (int i=1; i<=n; i++) p[arr[i].num]=i; int ori=1,start[n+1]; start[1]=1; for (int i=1; i<n; i++) { if (arr[i+1].s<=arr[i].f&&arr[i].f<=arr[i+1].f) start[i+1]=ori; else {ori=i+1; start[i+1]=ori;} } while (q--) { int a,b; cin>>a>>b; a=p[a]; b=p[b]; if (start[a]==start[b]&&a<=b) cout<<abs(a-b); else cout<<"impossible"; cout<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...