#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int r, c, n;
std::cin >> r >> c >> n;
std::vector<std::pair<int,int>> a(n + 1);
for(int i = 1; i <= n; i++) {
std::cin >> a[i].first >> a[i].second;
}
std::sort(a.begin() + 1, a.end());
std::map<std::pair<int,int>, int> M;
std::vector<int64_t> next(n + 1, 1e9 + 5);
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n; j++) {
if(a[i].first + 1 == a[j].first && a[i].second <= a[j].second) {
next[i] = j;
break;
}
}
}
std::vector<std::vector<int64_t>> jump(n + 1, std::vector<int64_t>(21));
for(int i = n; i >= 1; i--) {
jump[i][0] = next[i];
for(int bit = 1; bit < 21; bit++) {
int jump1 = jump[i][bit - 1];
if(jump1 > n) {
break;
}
int jump2 = jump[jump1][bit - 1];
if(jump2 > n) {
break;
}
jump[i][bit] = jump2;
}
}
int q;
std::cin >> q;
while(q--) {
int x1, y1, x2, y2;
std::cin >> x1 >> y1 >> x2 >> y2;
if(y1 > y2 || x2 < x1) {
std::cout << "No\n";
continue;
}
int index = - 1;
for(int i = 1; i <= n; i++) {
if(a[i].first == x1 && a[i].second >= y1) {
index = i;
break;
}
}
if(index == - 1) {
if(x1 != x2) {
std::cout << "No\n";
continue;
}
if(y1 <= y2) {
std::cout << "Yes\n";
}
else {
std::cout << "No\n";
}
continue;
}
//std::cout << index << " ";
for(int bit = 20; bit >= 0; bit--) {
int to = jump[index][bit];
if(to > n || to == 0) {
continue;
}
//std::cout << to << " ";
if(a[to].first < x2 && a[to].second <= y2) {
index = to;
}
}
if(a[index].first == x2 - 1 && a[index].second <= y2) {
std::cout << "Yes\n";
}
else {
std::cout << "No\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... |