#include <bits/stdc++.h>
#define nemeshay ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
#define int long long
#define sigma signed
#define pb push_back
#define fr first
#define sc second
#define pii pair<int, int>
#define double long double
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define OK cout << "OK" << endl
#define Ok cout << "Ok" << endl
#define nosolve cout << "-1" << endl
#define ordered_set tree<int,
using namespace std;
const int N = 2e5 + 2, inf = 1e18 + 7, mod = 998244353;
pii a[N];
int used[N], p[N], anc[20][N];
sigma main() {
int R, C, n;
cin >> R >> C >> n;
for (int i = 1; i <= n; i++) cin >> a[i].fr >> a[i].sc;
sort (a + 1, a + n + 1);
for (int i = n; i > 0; i--) {
int l = 0, r = i - 1;
while (r - l > 1) {
int m = l + r >> 1;
if (a[m].fr < a[i].fr) l = m;
else r = m;
}
if (a[r].fr < a[i].fr) p[r] = i;
else if (a[l].fr < a[i].fr) p[l] = i;
}
for (int i = n; i > 0; i--) {
if (used[i]) continue;
int x = p[i], prev = i;
while (x) {
used[x] = 1;
anc[x][0] = prev;
for (int j = 1; j < 20; j++) anc[x][j] = anc[anc[x][j - 1]][j - 1];
prev = x, x = p[x];
}
}
int q;
cin >> q;
while (q--) {
int xs, ys, xf, yf;
cin >> xs >> ys >> xf >> yf;
if (xs > xf) {
NO;
continue;
}
if (xs == xf) {
YES;
continue;
}
auto check = [&](int ind) {
return xf - a[ind].fr > 1 || (a[ind].fr == xf - 1 && a[ind].sc <= yf);
};
int l = 1, r = n, ind = 0;
while (r - l > 1) {
int m = l + r >> 1;
if (check(m)) l = m;
else r = m;
}
if (check(r)) ind = r;
else if (check(l)) ind = l;
if (!ind || xf - a[ind].fr > 1) {
NO;
continue;
}
for (int i = 0; i < 20; i++) if ((xf - xs - 1) & (1 << i)) ind = anc[ind][i];
if (!ind || a[ind].sc < ys) YES;
else NO;
}
}
# | 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... |