#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
using namespace std;
map<int, vector<pair<int, int>>> M;
pair<int, int> pts[200001];
int nxt[200001], anc[200001][20];
int kth_anc(int u, int k){
for(int j = 19; j >= 0; j--){
if(k >= (1 << j)) u = anc[u][j], k -= (1 << j);
}
return u;
}
int main(){
cin.tie(0); cout.tie(0)->sync_with_stdio(false);
int r, c, n; cin >> r >> c >> n;
for(int i = 0; i < n; i++){
int x, y; cin >> x >> y;
M[x].push_back({y, i});
pts[i] = {x, y};
}
for(int i = 0; i < n; i++){
int x = pts[i].fi, y = pts[i].se;
if(M.count(x + 1) && lower_bound(all(M[x + 1]), pair<int, int>{y, -1}) != M[x + 1].end()){
pair<int, int> p = *lower_bound(all(M[x + 1]), pair<int, int>{y, -1});
nxt[i] = p.se;
}else{
nxt[i] = i;
}
}
for(int j = 0; j < n; j++) anc[j][0] = nxt[j];
for(int i = 1; i < 20; i++){
for(int j = 0; j < n; j++){
anc[j][i] = anc[anc[j][i - 1]][i - 1];
}
}
for(auto& i : M) sort(all(i.second));
int q; cin >> q;
for(int i = 0; i < q; i++){
int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
if(r1 == r2 && c1 <= c2) { cout << "Yes" << endl; continue; }
if(c1 > c2 || r1 > r2) { cout << "No" << endl; continue; }
if(M.count(r1) && lower_bound(all(M[r1]), pair<int, int>{c1, -1}) != M[r1].end()){
int fr = lower_bound(all(M[r1]), pair<int, int>{c1, -1})->se;
int v = kth_anc(fr, r2 - r1 - 1);
if(pts[v].fi != r2 - 1 || pts[v].se > c2) { cout << "No" << endl; continue; }
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1236 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
188 ms |
23336 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
32804 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
472 ms |
32768 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
499 ms |
32956 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
576 ms |
33464 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
579 ms |
33444 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
762 ms |
39204 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
1108 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
885 ms |
40372 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |