#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nmax = 2e5 + 5, inf = 1e18;
int rmq[nmax][17];
struct punct {
int a, b, i;
int x;
const bool operator < (punct ult) const {
if(ult.a != a) {
return a > ult.a;
}
return b < ult.b;
}
} v[nmax];
map<int, int> f;
void normalize(int n) {
for(int i = 1; i <= n; i++) {
f[v[i].a];
}
int cnt = 1;
for(auto &it : f) {
it.second = cnt++;
}
for(int i = 1; i <= n; i++) {
v[i].x = f[v[i].a];
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int useless, n;
cin >> useless >> useless >> n;
for(int i = 1; i <= n; i++) {
cin >> v[i].a >> v[i].b;
v[i].i = i;
}
sort(v + 1, v + n + 1);
normalize(n);
v[0].b = inf;
vector<vector<pair<int, int>>> poz(f.size() + 5);
for(int i = 1; i <= n; i++) {
poz[v[i].x].push_back({v[i].b, i});
}
for(int i = 1; i <= n; i++) {
if(f.find(v[i].a + 1) == f.end()) {
continue;
}
int l = 0, r = poz[v[i].x + 1].size() - 1, ans = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(poz[v[i].x + 1][mid].first >= v[i].b) {
ans = poz[v[i].x + 1][mid].second;
r = mid - 1;
} else {
l = mid + 1;
}
}
// cout << i << ": " << ans << '\n';
rmq[i][0] = ans;
for(int j = 1; (1 << j) <= n; j++) {
rmq[i][j] = rmq[rmq[i][j - 1]][j - 1];
}
}
int q;
cin >> q;
while(q--) {
int a, b, x, y;
cin >> a >> b >> x >> y;
if(a > x || b > y || x - a > n + 1) {
cout << "No\n";
continue;
}
if(a == x) {
cout << "Yes\n";
continue;
} else if(f.find(a) == f.end()) {
cout << "No\n";
continue;
}
int dif = x - a - 1;
a = f[a];
int l = 0, r = poz[a].size() - 1, i = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(poz[a][mid].first >= b) {
i = poz[a][mid].second;
r = mid - 1;
} else {
l = mid + 1;
}
}
// cout << dif << '\n';
for(int bit = 0; (1 << bit) <= dif; bit++) {
if(dif & (1 << bit)) {
i = rmq[i][bit];
}
}
cout << (v[i].b <= y ? "Yes\n" : "No\n");
}
return 0;
}
# | 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... |