Submission #745190

#TimeUsernameProblemLanguageResultExecution timeMemory
745190sword060Osumnjičeni (COCI21_osumnjiceni)C++17
30 / 110
1083 ms5532 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5+5,M=18; int x,q,l[N],r[N],nxt[N][20]; int main(){ ios::sync_with_stdio(0);cin.tie(0); cin>>x; for(int i=1;i<=x;i++)cin>>l[i]>>r[i]; for(int i=1;i<=x;i++){ nxt[i][0]=nxt[i-1][0]; for(int j=1;j<i;j++) if(max(l[i],l[j])<=min(r[i],r[j])) nxt[i][0]=max(nxt[i][0],j); for(int j=1;j<=M;j++) nxt[i][j]=nxt[nxt[i][j-1]][j-1]; } cin>>q; while(q--){ int c1,c2,ans=1;cin>>c1>>c2; for(int i=M;i>=0;i--) if(nxt[c2][i]>=c1) c2=nxt[c2][i],ans+=(1<<i); cout<<ans<<"\n"; } }
#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...