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 = 1e5+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 j=0;j<=M;j++)nxt[x+1][j]=x+1;
for(int i=x;i>=1;i--){
nxt[i][0]=(i<x?nxt[i+1][0]:i+1);
for(int j=x;j>i;j--)
if(max(l[i],l[j])<=min(r[i],r[j]))
nxt[i][0]=min(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[c1][i]<=c2)
c1=nxt[c1][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... |