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=5e5+5;
const int K=1<<20;
const int INF=INT_MAX/2;
int n,m,q;
vector<int> upd[N];
vector<pair<int,int>> qrs[N];
bool ans[N];
struct SegTree{
struct Node{
int mn,mn2;
Node():mn(0),mn2(INF){}
Node(int _mn,int _mn2):mn(_mn),mn2(_mn2){}
friend Node operator+(const Node &lhs,const Node &rhs){
if(lhs.mn<rhs.mn)return Node(lhs.mn,min(rhs.mn,lhs.mn2));
if(lhs.mn>rhs.mn)return Node(rhs.mn,min(lhs.mn,rhs.mn2));
return Node(lhs.mn,min(lhs.mn2,rhs.mn2));
}
void chmax(int v){
if(v<=mn)return;
mn=v;
if(mn>=mn2)mn2=INF;
}
}t[K];
void push(int i){
t[i*2].chmax(t[i].mn);
t[i*2+1].chmax(t[i].mn);
}
void update(int l,int r,int i,int x,int y,int v){
if(y<l||r<x||t[i].mn>=v)return;
if(x<=l&&r<=y&&t[i].mn2>v)return t[i].chmax(v);
push(i);
int m=(l+r)/2;
update(l,m,i*2,x,y,v);
update(m+1,r,i*2+1,x,y,v);
t[i]=t[i*2]+t[i*2+1];
}
void update(int x,int y,int v){
update(1,n,1,x,y,v);
}
int query(int l,int r,int i,int x,int y){
if(y<l||r<x)return INF;
if(x<=l&&r<=y)return t[i].mn;
push(i);
int m=(l+r)/2;
return min(query(l,m,i*2,x,y),query(m+1,r,i*2+1,x,y));
}
int query(int x,int y){
return query(1,n,1,x,y);
}
}seg;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m >> q;
for(int i=0;i<m;i++){
int l,r;
cin >> l >> r;
upd[r].emplace_back(l);
}
for(int i=0;i<q;i++){
int l,r;
cin >> l >> r;
qrs[r].emplace_back(l,i);
}
for(int r=1;r<=n;r++){
for(auto l:upd[r]){
seg.update(l,r,l);
}
for(auto [l,i]:qrs[r]){
ans[i]=(seg.query(l,r)>=l);
}
}
for(int i=0;i<q;i++){
cout << (ans[i]?"YES":"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... |