#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 = 3e5 + 7;
int x[N], y[N], to1[N], res[N], used[N];
map<int, set<int>>mp;
pair<int, int>to[N];
map<pair<int, int>, int>mp1;
vector<array<int, 3>>query[N];
vector<int>g1[N];
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};
}
}
void dfs(int v){
used[v] = 1;
mp[x[v]].ins(y[v]);
for(auto [i, a, b] : query[v]){
if(mp[a - 1].size() && *mp[a - 1].begin() <= b) res[i] = 1;
}
for(auto to : g1[v]){
dfs(to);
}
mp[x[v]].erase(mp[x[v]].find(y[v]));
}
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]];
}
g1[to1[i]].pb(i);
}
cin>>t;
for(int j = 1; j <= t; j++){
int a, b;
cin>>a>>b>>c>>d;
if(a == c && b <= d){
res[j] = 1;
continue;
}
if(!mp[a].size() || a > c || b > d){
continue;
}
auto it = mp[a].lower_bound(b);
if(it != mp[a].end()){
b = *it;
}
int i = mp1[{a, b}];
query[i].pb({j, c, d});
}
sort(all(v));
reverse(all(v));
for(auto [a, b, i] : v){
if(!used[i]) dfs(i);
}
for(int i = 1; i <= t; i++){
if(res[i]) 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();
}
}
# | 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... |