#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 |
1364 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 |
1236 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
21416 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
84 ms |
21688 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
77 ms |
20812 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
85 ms |
21620 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
21484 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
186 ms |
21512 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
183 ms |
21216 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
274 ms |
21832 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
236 ms |
21764 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
421 ms |
27604 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
980 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
1236 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
8 ms |
1620 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
1216 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
11 ms |
1368 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
1240 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
583 ms |
28828 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
421 ms |
23968 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
213 ms |
21460 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
670 ms |
41164 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
362 ms |
28112 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
211 ms |
21808 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
202 ms |
21792 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
204 ms |
21352 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
571 ms |
27772 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
569 ms |
27984 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
656 ms |
33920 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
204 ms |
20884 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
184 ms |
21248 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
268 ms |
21832 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
187 ms |
21328 KB |
200000 token(s): yes count is 129674, no count is 70326 |