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;
constexpr int NMAX = 2e5 + 5;
struct trampoline {
int x, y;
};
trampoline a[NMAX];
int R, C, N;
int dad[30][NMAX];
bool viz[NMAX];
vector <int> G[NMAX];
int T;
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> R >> C >> N;
for (int i = 1; i <= N; ++ i )
cin >> a[i].x >> a[i].y;
}
bool cmp (trampoline a, trampoline b) {
if (a.x < b.x) return false;
if (a.x == b.x && a.y < b.y) return false;
return true;
}
void Precalculare_Graf () {
sort(a+1, a+N+1, cmp);
for (int i = 1; i <= N; ++ i ) {
int st = 1, dr = i-1;
int ind = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (a[mij].x > a[i].x+1) st = mij + 1;
else if (a[mij].x < a[i].x+1) dr = mij - 1;
else {
if (a[mij].y < a[i].y) dr = mij - 1;
else {
st = mij + 1;
ind = mij;
}
}
}
dad[0][i] = ind;
}
for (int i = 1; i <= N; ++ i ) {
if (dad[0][i] == -1) continue;
G[dad[0][i]].push_back(i);
}
}
void Build_Rmq (int node) {
viz[node] = 1;
for (int putere = 1; putere <= 20; ++ putere)
dad[putere][node] = dad[putere-1][dad[putere-1][node]];
for (auto it : G[node])
Build_Rmq(it);
}
int Who (int K, int node) {
int ans = node;
for (int putere = 0; putere <= 20 && ans != -1; ++ putere )
if ((K&(1<<putere)))
ans = dad[putere][ans];
return ans;
}
void Solve () {
cin >> T;
for (; T; -- T ) {
int x, y, End_x, End_y;
cin >> x >> y >> End_x >> End_y;
if (x > End_x) {
cout << "No" << '\n';
continue;
}
else if (x == End_x) {
if (y <= End_y)
cout << "Yes" << '\n';
else cout << "No" << '\n';
continue;
}
int st = 1, dr = N;
int ind = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (a[mij].x > x) st = mij + 1;
else if (a[mij].x < x) dr = mij - 1;
else {
if (a[mij].y < y) dr = mij - 1;
else {
ind = mij;
st = mij+1;
}
}
}
int node = Who(End_x - x - 1, ind);
if (node != -1 && a[node].y <= End_y)
cout << "Yes\n";
else cout << "No\n";
}
}
int main()
{
Read();
Precalculare_Graf();
for (int i = 1; i <= N; ++ i )
if (!viz[i]) Build_Rmq(i);
Solve();
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... |