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 int long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
using namespace std;
void _(){
int r,c,n;
cin >> r >> c >> n;
array<int,2> ar[n+5];
for(int i=1;i<=n;i++) cin >> ar[i][0] >> ar[i][1];
map<int,vector<int>> mp;
map<array<int,2>,int> rev;
for(int i=1;i<=n;i++) rev[ar[i]]=i;
for(int i=1;i<=n;i++) mp[ar[i][0]].push_back(ar[i][1]);
for(auto x : mp) sort(all(mp[x.first]));
int lift[n+5][20];
for(int i=1;i<=n;i++){
int a=ar[i][0],b=ar[i][1];
int it = lower_bound(all(mp[a+1]),b) - mp[a+1].begin();
if(it == sz(mp[a+1])) lift[i][0] = i;
else lift[i][0] = rev[{a+1,mp[a+1][it]}];
}
for(int j=1;j<20;j++){
for(int i=1;i<=n;i++){
lift[i][j]=lift[lift[i][j-1]][j-1];
}
}
int q; cin >> q;
while(q--){
int a,b,c,d;
cin >> a >> b >> c >> d;
if(a==c){
if(b<=d) cout << "Yes\n";
else cout << "No\n";
continue;
}
if(a>c){
cout << "No\n";
continue;
}
int it = lower_bound(all(mp[a]),b) - mp[a].begin();
if(it == sz(mp[a])){
cout << "No\n";
continue;
}
int p = rev[{a,mp[a][it]}];
for(int i=19;i>=0;i--){
int A = ar[lift[p][i]][0];
int B = ar[lift[p][i]][1];
if(A>=c) continue;
p = lift[p][i];
}
if(ar[p][0] + 1 < c){
cout << "No\n";
continue;
}
if(ar[p][1] <= d) cout << "Yes\n";
else cout << "No\n";
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int tc=1;//cin >> tc;
while(tc--) _();
}
Compilation message (stderr)
trampoline.cpp: In function 'void _()':
trampoline.cpp:55:11: warning: unused variable 'B' [-Wunused-variable]
55 | int B = ar[lift[p][i]][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... |