#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";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2512 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
7 ms |
2896 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
6 ms |
2132 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
50228 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
180 ms |
51884 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
160 ms |
50928 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
181 ms |
51968 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
754 ms |
49964 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
753 ms |
61380 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
769 ms |
61608 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
830 ms |
62192 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
794 ms |
62152 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
957 ms |
68148 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
1492 KB |
expected NO, found YES [16th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1128 ms |
57844 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Incorrect |
997 ms |
64192 KB |
expected NO, found YES [22020th token] |
3 |
Halted |
0 ms |
0 KB |
- |