#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define ins insert
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const int N = 2e5 + 7;
int x[N], y[N], to1[N];
map<int, set<int>>mp;
pair<int, int>to[N];
int up[N][18];
map<pair<int, int>, int>mp1;
int c, d;
pair<int, int>next(int a, int b){
if(mp[a + 1].size()){
auto it = mp[a + 1].lower_bound(b);
if(it != mp[a + 1].end()){
return {a + 1, *it};
}
else{
return {-1, -1};
}
}
else{
return {-1, -1};
}
}
int check(int i, int m){
for(int j = 0; j < 18; j++){
if((m>>j) & 1) i = up[i][j];
}
if(i == 0) return 2;
if(x[i] >= c) return 2;
if(x[i] < c - 1) return 0;
if(x[i] == c - 1) return 1;
}
void solve(){
int r, w, n, t;
cin>>r>>w>>n;
vector<array<int, 3>>v;
for(int i = 1; i <= n; i++){
cin>>x[i]>>y[i];
mp1[{x[i], y[i]}] = i;
mp[x[i]].ins(y[i]);
v.pb({x[i], y[i], i});
}
for(int i = 1; i <= n; i++){
to[i] = next(x[i], y[i]);
if(to[i].F == -1 && to[i].S == -1){
auto it = mp[x[i]].upper_bound(y[i]);
if(it != mp[x[i]].end()){
to[i] = {x[i], *it};
}
}
if(to[i].F != -1 && to[i].S != -1){
to1[i] = mp1[to[i]];
}
}
sort(all(v));
reverse(all(v));
for(auto [a, b, i] : v){
up[i][0] = to1[i];
for(int j = 1; j < 18; j++){
up[i][j] = up[up[i][j - 1]][j - 1];
}
}
cin>>t;
while(t--){
int a, b;
cin>>a>>b>>c>>d;
if(a == c && b <= d){
cout<<"YES\n";
continue;
}
if(!mp[a].size() || a > c || b > d){
cout<<"NO\n";
continue;
}
auto it = mp[a].lower_bound(b);
if(it != mp[a].end()){
b = *it;
}
int i = mp1[{a, b}];
int l = 0, r = 2e5 + 7, res = -1;
while(l <= r){
int m = (l + r) / 2;
int f = check(i, m);
if(f == 1){
r = m - 1;
res = m;
}
else if(f == 2){
r = m - 1;
}
else{
l = m + 1;
}
}
if(res == -1){
cout<<"NO\n";
continue;
}
for(int j = 0; j < 18; j++){
if((res>>j) & 1){
i = up[i][j];
}
}
if(x[i] == c - 1 && y[i] <= d){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
}
signed main(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin>>t;
while(t--){
solve();
}
}
Compilation message (stderr)
trampoline.cpp: In function 'int check(int, int)':
trampoline.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
42 | }
| ^
# | 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... |