This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |