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;
#define int long long
int par[200005];
pair<int,int>arr[200005];
map<pair<int,int>,int>m;
int twok[200005][21];
int findp(int x, int k){
for(int i=0; i<21; i++){
if(k&(1<<i)) x=twok[x][i];
if(x==-1) return -1;
}
return x;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int r,c,n; cin>>r>>c>>n;
for(int i=0; i<n; i++){
int a,b; cin>>a>>b;
arr[i] = {a,b};
}
sort(arr,arr+n);
int cnt=0;
for(auto i: arr) m[i] = cnt, cnt++;
for(int i=0; i<n; i++){
pair<int,int>p = arr[i];
p.first++;
auto it = lower_bound(arr,arr+n,p);
if(it==arr+n) par[i] = -1;
else if(it->first > p.first) par[i] = -1;
else par[i] = it-arr;
}
for(int i=0; i<n; i++) twok[i][0] = par[i];
for(int k=1; k<21; k++){
for(int x=0; x<n; x++){
int half = twok[x][k-1];
if(half==-1) twok[x][k] = -1;
else twok[x][k] = twok[half][k-1];
}
}
int t; cin>>t;
while(t--){
int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
if(x2<x1 or y2<y1){cout<<"No\n"; continue;}
if(x1==x2){cout<<"Yes\n"; continue;}
pair<int,int>p = {x1,y1};
auto it = lower_bound(arr,arr+n,p);
if(it==arr+n){cout<<"No\n"; continue;}
if(it->first > x1){cout<<"No\n"; continue;}
int P = findp(m[*it],x2-x1-1);
if(P==-1 or arr[P].second > y2)cout<<"No\n";
else cout<<"Yes\n";
}
return 0;
}
# | 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... |