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> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,k,q,dp[2000005][30];
pair<ll,ll>a[200005];
ll calc(ll x,ll y){
ll l=1,r=k,ans=k+1;
while(l<=r){
ll mid=(l+r)/2;
if(a[mid]>=mp(x,y)){
ans=mid;
r=mid-1;
}else l=mid+1;
}
if(ans==k+1){
return 0;
}
if(a[ans].f>x){
return 0;
}
return ans;
}
int32_t main(){
CODE_START;
cin>>n>>m>>k;
for(ll i=1;i<=k;i++)
{
cin>>a[i].f>>a[i].s;
}
a[0]=mp(LINF,LINF);
sort(a+1,a+k+1);
for(ll i=1;i<=k;i++)
{
dp[i][0]=calc(a[i].f+1,a[i].s);
}
for(ll j=1;j<30;j++)
{
for(ll i=1;i<=k;i++)
{
dp[i][j]=dp[dp[i][j-1]][j-1];
}
}
cin>>q;
while(q--){
ll x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
if(x2<x1){
cout<<"No"<<endl;
continue;
}
if(y2<y1){
cout<<"No"<<endl;
continue;
}
if(x1==x2){
cout<<"Yes"<<endl;
continue;
}
ll pos=calc(x1,y1),l=x2-x1-1;
for(ll j=0;j<30;j++)
{
if(l&(1<<j)){
pos=dp[pos][j];
}
}
if(a[pos].s<=y2){
cout<<"Yes"<<endl;
}else cout<<"No"<<endl;
}
}
# | 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... |