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"
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,ull>pairull;
typedef pair<ll,pairll>pair3l;
typedef long double ld;
typedef pair<ld,ll>pairld;
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define N 100007
//#define MOD 998244353
#define INF 100000000000007
#define eps 0.0000000001
ll n,m,k,h,p[36][2*N];
struct D{
ll l,r;
}d[2*N];
map<ll,ll>mp;
vector<pairll>v[2*N];
bool mcp(D d1, D d2){
if(d1.l!=d2.l)return d1.l<d2.l;
return d1.r<d2.r;
}
ll P(ll x,ll y){
for(int i=30;i>=0;i--){
ll g=p[i][x];
if(d[g].l<y)x=g;
}
return x;
}
int main(){
cin>>n>>m>>k;
for(int i=1;i<=k;i++){
cin>>d[i].l>>d[i].r;
}
sort(d+1,d+1+k,mcp);
for(int i=1;i<=k;i++){
if(d[i].l!=d[i-1].l){
h++;
mp[d[i].l]=h;
}
v[h].pb({d[i].r,i});
}
for(int i=1;i<=k;i++){
if(mp[d[i].l+1]==0){
p[0][i]=k+1;
}else{
ll l=0;
ll nm=mp[d[i].l+1];
ll r=v[nm].size();
while(l<r){
ll m1=(l+r)/2;
if(v[nm][m1].fr>=d[i].r)r=m1;
else l=m1+1;
}
if(r==v[nm].size())p[0][i]=k+1;
else p[0][i]=v[nm][r].sc;
}
}
p[0][k+1]=k+1;
for(int i=1;i<=30;i++){
for(int j=1;j<=k+1;j++){
p[i][j]=p[i-1][p[i-1][j]];
}
}
d[k+1].l=INF;
ll q;
cin>>q;
for(int i=1;i<=q;i++){
ll x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
if(y1>y2 || x1>x2){
cout<<"No"<<endl;
}
else if(x1==x2){
cout<<"Yes"<<endl;
}else{
if(mp[x1]==0){
cout<<"No"<<endl;
continue;
}
ll l=0;
ll nm=mp[x1];
ll r=v[nm].size();
while(l<r){
ll m1=(l+r)/2;
if(v[nm][m1].fr>=y1){
r=m1;
}else l=m1+1;
}
h=0;
if(r==v[nm].size())h=k+1;
else h=v[nm][r].sc;
h=P(h,x2);
if(d[h].l==x2-1 && d[h].r<=y2)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return 0;
}
Compilation message (stderr)
trampoline.cpp: In function 'int main()':
trampoline.cpp:73:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if(r==v[nm].size())p[0][i]=k+1;
| ~^~~~~~~~~~~~~~
trampoline.cpp:109:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | if(r==v[nm].size())h=k+1;
| ~^~~~~~~~~~~~~~
# | 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... |