#include <bits/stdc++.h>
using namespace std;
void main_program();
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
main_program();
}
int R, C, n, q;
vector<pair<int, int>> inp;
map<int, vector<pair<int, int>>> mp;
int nxt[21][200'005];
void main_program(){
cin >> R >> C >> n;
inp.resize(n+1);
for (int i = 0; i < n; i++){
int a, b; cin >> a >> b;
inp[i+1] = {a, b};
mp[a].emplace_back(b, i+1);
}
for (auto &[key, value]: mp){
sort(value.begin(), value.end());
}
for (int i = 0; i <= n; i++) nxt[0][i] = 0;
for (auto it = mp.rbegin(); it != mp.rend(); it++){
auto [x, vy] = *it;
if (!mp.count(x+1)) continue;
for (auto [y, i]: vy){
auto it2 = lower_bound(mp[x+1].begin(), mp[x+1].end(), make_pair(y, -1));
if (it2 == mp[x+1].end()) continue;
auto [x2, j] = *it2;
// cout << "EDGE " << i << " " << j << "\n";
nxt[0][i] = j;
}
}
for (int lg = 1; lg < 21; lg++){
for (int i = 0; i <= n; i++){
nxt[lg][i] = nxt[lg-1][nxt[lg-1][i]];
}
}
cin >> q;
for (int qr = 0; qr < q; qr++){
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2){
cout << "No\n";
continue;
}
if (x1 == x2){
if (y1 <= y2) cout << "Yes\n";
else cout << "No\n";
continue;
}
if (y1 > y2){
cout << "No\n";
continue;
}
int D = x2 - x1 - 1;
int crr = 0;
if (mp.count(x1)){
auto it = lower_bound(mp[x1].begin(), mp[x1].end(), make_pair(y1, -1));
if (it != mp[x1].end()){
crr = (*it).second;
}
}
// cout << ":: " << crr << "\n";
for (int lg = 20; lg >= 0; lg--){
if ((D >> lg) & 1) crr = nxt[lg][crr];
}
if (!crr) cout << "No\n";
else{
if (inp[crr].second <= y2) cout << "Yes\n";
else cout << "No\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1316 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
1492 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
1196 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
21388 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
107 ms |
21376 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
72 ms |
20612 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
84 ms |
21364 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
21496 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
181 ms |
21468 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
196 ms |
21328 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
251 ms |
21732 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
221 ms |
21680 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
404 ms |
27644 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
980 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
5 ms |
996 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
7 ms |
1456 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
980 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
6 ms |
1108 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
4 ms |
980 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
530 ms |
28840 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
428 ms |
23900 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
196 ms |
21304 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
739 ms |
40968 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
433 ms |
27872 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
235 ms |
21660 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
213 ms |
21652 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
218 ms |
21176 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
617 ms |
27612 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
634 ms |
27792 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
670 ms |
33756 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
204 ms |
20716 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
337 ms |
21120 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
277 ms |
21708 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
309 ms |
21268 KB |
200000 token(s): yes count is 129674, no count is 70326 |