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 <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;
const int MAXN = 2e5 + 123;
pair<int, int> pts[MAXN];
vector<int> ptr[MAXN];
int rt[MAXN];
int crt[MAXN];
int depth[MAXN];
int fup(int v, int x1) {
if (pts[v].first >= x1 || rt[v] == v)
return v;
if (pts[crt[v]].first <= x1)
return fup(crt[v], x1);
return fup(rt[v], x1);
}
signed main() {
int r, c, n;
cin >> r >> c >> n;
vector<int> cprx;
for (int i = 0; i < n; ++i) {
cin >> pts[i].first >> pts[i].second;
cprx.push_back(pts[i].first);
cprx.push_back(pts[i].first + 1);
}
sort(cprx.begin(), cprx.end());
cprx.resize(unique(cprx.begin(), cprx.end()) - cprx.begin());
int csz = cprx.size();
sort(pts, pts + n);
for (int i = 0; i < n; ++i) {
int x = lower_bound(cprx.begin(), cprx.end(), pts[i].first) - cprx.begin();
pts[i].first = x;
ptr[x].push_back(pts[i].second);
}
for (int i = 0; i < n; ++i) {
int x = pts[i].first;
int j = lower_bound(pts, pts + n, pair<int, int>(x + 1, pts[i].second)) - pts;
if (j == n || pts[j].first != x + 1) {
rt[i] = i;
} else {
rt[i] = j;
}
}
//for (int i = 0; i < n; ++i) {
//cout << i << ": (" << cprx[pts[i].first] << ' ' << ' ' << pts[i].second << ") : " << rt[i] << "\n";
//}
for (int v = n - 1; v >= 0; --v) {
crt[v] = rt[v];
if (rt[v] == v)
continue;
depth[v] = depth[rt[v]] + 1;
if (depth[rt[v]] + depth[crt[crt[rt[v]]]] == 2 * depth[crt[rt[v]]])
crt[v] = crt[crt[rt[v]]];
}
int T;
cin >> T;
for (int t = 0; t < T; ++t) {
pair<int, int> p0, p1;
cin >> p0.first >> p0.second >> p1.first >> p1.second;
if (p0.first > p1.first || p0.second > p1.second) {
cout << "No\n";
continue;
}
if (p0.first == p1.first) {
cout << "Yes\n";
continue;
}
int x0 = lower_bound(cprx.begin(), cprx.end(), p0.first) - cprx.begin();
int x1 = lower_bound(cprx.begin(), cprx.end(), p1.first) - cprx.begin();
if (x1 == csz || p0.first != cprx[x0] || p1.first != cprx[x1]) {
cout << "No\n";
continue;
}
p0.first = x0;
p1.first = x1;
int v = lower_bound(pts, pts + n, p0) - pts;
//cout << "HAHA " << v << endl;
if (pts[v].first != x0) {
cout << "No\n";
continue;
}
int u = fup(v, x1 - 1);
if (pts[u].first != x1 - 1 || pts[u].second > p1.second) {
cout << "No\n";
continue;
}
cout << "Yes\n";
}
}
# | 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... |