#include "bits/stdc++.h"
using namespace std;
const long long MX=2e6;
vector < pair < long long , long long > > mas[MX];
set < pair < long long , long long > > ab;
vector < long long > reb[MX];
map < long long , long long > as;
long long r,c,n;
long long uk=0,nm=0;
void cnt() {
for (auto u: ab) {
as[u.first - 1]++;
as[u.first]++;
as[u.first + 1]++;
}
for (auto &u: as) {
uk++;
u.second = uk;
}
for (auto u: ab) {
nm++;
mas[as[u.first]].push_back({u.second, nm});
}
for (long long i = 1; i <= uk; i++) {
nm++;
mas[i].push_back({c + 1, nm});
}
}
long long tin[MX],tou[MX];
long long timer=0;
void DFS(long long zar) {
timer++;
tin[zar] = timer;
for (auto u: reb[zar]) {
DFS(u);
}
timer++;
tou[zar] = timer;
}
void cnt2() {
for (long long i = 1; i < uk; i++) {
for (auto u: mas[i]) {
long long frm = (*lower_bound(mas[i + 1].begin(), mas[i + 1].end(), make_pair(u.first, 0LL))).second;
reb[frm].push_back(u.second);
}
}
DFS(mas[uk][0].second);
}
void zap() {
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 >= x2) {
cout << (((y1 <= y2) && (x1 == x2)) ? "Yes" : "No") << "\n";
return;
}
if (as.find(x1) == as.end() || as.find(x2 - 1) == as.end()) {
cout << "No\n";
return;
}
long long rlx1 = as[x1], rlx2 = as[x2 - 1];
if (y2 < mas[rlx2][0].first) {
cout << "No\n";
}
pair<long long, long long> frb = (*lower_bound(mas[rlx1].begin(), mas[rlx1].end(), make_pair(y1, 0LL)));
pair<long long, long long> srb = (*(upper_bound(mas[rlx2].begin(), mas[rlx2].end(), make_pair(y2, 0LL))--));
if (tin[mas[rlx2][0].second] <= tin[frb.second] && tou[frb.second] <= tou[srb.second]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> r >> c >> n;
long long a, b;
for (long long i = 1; i <= n; i++) {
cin >> a >> b;
ab.insert({a, b});
}
cnt();
cnt2();
long long q;
cin >> q;
while (q--) {
zap();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
97628 KB |
expected NO, found YES [7th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
232 ms |
122400 KB |
expected NO, found YES [22nd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
295 ms |
120024 KB |
expected NO, found YES [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
97372 KB |
expected NO, found YES [43rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
530 ms |
135604 KB |
expected NO, found YES [22nd token] |
2 |
Halted |
0 ms |
0 KB |
- |