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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
using namespace std;
const int mxn=5e5+5;
vector<int>upd[mxn];
vector<pii>qr[mxn];
int t[4*mxn],lz[4*mxn]{0};
void build(int i,int l,int r){
lz[i]=1e9;
if(l==r)return void(t[i]=1e9);
int m=(l+r)>>1;build(2*i,l,m);build(2*i+1,m+1,r);
t[i]=max(t[2*i],t[2*i+1]);
}
void push(int i,int l,int r){
t[i]=min(t[i],lz[i]);
if(l<r)lz[2*i]=min(lz[2*i],lz[i]),lz[2*i+1]=min(lz[2*i+1],lz[i]);
lz[i]=1e9;
}
void update(int i,int l,int r,int tl,int tr,int v){
push(i,l,r);
if(r<tl||l>tr)return;
if(r<=tr&&l>=tl){
lz[i]=min(lz[i],v);push(i,l,r);return;
}int m=(l+r)>>1;update(2*i,l,m,tl,tr,v);update(2*i+1,m+1,r,tl,tr,v);
t[i]=max(t[2*i],t[2*i+1]);
}
int query(int i,int l,int r,int tl,int tr){
push(i,l,r);
if(r<tl||l>tr)return 0;
if(r<=tr&&l>=tl)return t[i];
int m=(l+r)>>1;
return max(query(2*i,l,m,tl,tr),query(2*i+1,m+1,r,tl,tr));
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,q;cin>>n>>m>>q;
for(int i=1;i<=m;i++){
int l,r;cin>>l>>r;
upd[l].pb(r);
}
for(int i=1;i<=q;i++){
int l,r;cin>>l>>r;
qr[l].pb({r,i});
}build(1,1,n);int ans[q+1]={0};
for(int i=n;i>=1;i--){
for(auto it : upd[i])update(1,1,n,i,it,it);
for(auto it : qr[i])ans[it.s]=(query(1,1,n,i,it.f)<=it.f);
}
for(int i=1;i<=q;i++)cout<<(ans[i]?"YES\n":"NO\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |