#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#define int long long
using namespace std;
const int N = 2e5 + 10;
map <int, vector<int>> mp;
map <pair<int, int>, int> yp;
vector <pair<int, int>> v;
int a[N];
int dp[N][20];
int ans(int x, int y, int cnt) {
int u = yp[{x, y}];
for (int i = 19; i >= 0; i--) {
if (cnt & (1 << i)) u = dp[u][i];
if (u == -1) return 1e9 + 10;
}
return v[u].second;
}
signed main()
{
int r, c, n;
cin >> r >> c >> n;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
mp[a].push_back(b);
}
for (auto it : mp) {
sort(it.second.begin(), it.second.end());
}
int cnt = -1;
for (auto it : mp) {
for (auto j : it.second) {
v.push_back({ it.first, j });
yp[{it.first, j}] = ++cnt;
}
}
for (int i = n - 1; i >= 0; i--) {
if (v[i].first == v.back().first) {
for (int j = 0; j <= 19; j++) {
dp[i][j] = -1;
}
}
else {
auto it = mp.find(v[i].first); it++;
if (it->first > v[i].first + 1) dp[i][0] = -1;
else if (it->second.back() < v[i].second) dp[i][0] = -1;
else {
int k = lower_bound(it->second.begin(), it->second.end(), v[i].second) - it->second.begin();
dp[i][0] = yp[{v[i].first + 1, it->second[k]}];
}
for (int j = 1; j <= 19; j++) {
if (dp[i][j - 1] == -1) {
dp[i][j] = -1;
continue;
}
dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
}
}
int q;
cin >> q;
while (q--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == c) {
cout << "Yes\n";
continue;
}
if (mp.find(a) == mp.end()) {
cout << "No\n";
continue;
}
auto it = mp.find(a);
if (it->second.back() < b) {
cout << "No\n";
continue;
}
int j = lower_bound(it->second.begin(), it->second.end(), b) - it->second.begin();
int l = ans(a, it->second[j], c - a - 1);
if (l <= d) cout << "Yes\n";
else cout << "No\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
2512 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
168 ms |
51880 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
669 ms |
61420 KB |
expected YES, found NO [4th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
1876 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
973 ms |
69260 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |