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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 2e5 + 5;
vector<int> cmp, row[mn];
int nxt[mn][18], x[mn], y[mn];
bool found (int targ) {
auto it = lower_bound(all(cmp), targ);
return it != cmp.end() && *it == targ;
}
int getID (int targ) {
return lower_bound(all(cmp), targ) - cmp.begin() + 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int r, c, n; cin >> r >> c >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
cmp.push_back(x[i]);
}
sort(all(cmp)), filter(cmp);
for (int i = 1; i <= n; i++)
row[getID(x[i])].push_back(i);
for (int i = 1; i <= n; i++)
sort(all(row[i]), [&] (int a, int b) { return y[a] < y[b]; });
for (int i = 1; i <= n; i++) {
if (!found(x[i] + 1)) continue;
int cur = getID(x[i] + 1);
auto it = lower_bound(all(row[cur]), y[i],
[&] (int a, int b) { return y[a] < b; });
if (it != row[cur].end()) nxt[i][0] = *it;
}
for (int s = 1; s < 18; s++)
for (int i = 1; i <= n; i++)
nxt[i][s] = nxt[nxt[i][s - 1]][s - 1];
int q; cin >> q;
while (q--) {
int stx, sty, enx, eny; cin >> stx >> sty >> enx >> eny;
if (stx > enx || enx - stx - 1 > n) {
cout << "No\n";
continue;
}
else if (stx == enx) {
cout << (sty <= eny ? "Yes" : "No") << "\n";
continue;
}
else {
int curRow = getID(stx);
auto it = lower_bound(all(row[curRow]), sty,
[&] (int a, int b) { return y[a] < b; });
if (it == row[curRow].end()) {
cout << "No\n";
continue;
}
int cur = *it;
for (int step = enx - stx - 1, i = 0; step; step >>= 1, i++)
if (step & 1) cur = nxt[cur][i];
cout << (cur && y[cur] <= eny ? "Yes" : "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... |