#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int rv[MAXN], cv[MAXN], nxt[MAXN][20];
map<int, vector<pair<int, int>>> m;
int xpar(int a, int x){
for (int k = 19; k >= 0; k--){
if (a == -1) break;
if (x & (1 << k)) a = nxt[a][k];
}
return a;
}
bool solve(){
int sr, sc, er, ec; cin >> sr >> sc >> er >> ec;
if (er < sr || ec < sc) return 0;
if (er == sr) return 1;
if (!m.count(sr)) return 0;
auto it = lower_bound(m[sr].begin(), m[sr].end(), make_pair(sc, -1));
if (it == m[sr].end()) return 0;
int finc = xpar(it->second, er - sr - 1);
if (finc == -1) return 0;
return cv[finc] <= ec;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int rows, cols, nums; cin >> rows >> cols >> nums;
for (int i = 0; i < nums; i++){
int r, c; cin >> r >> c;
rv[i] = r; cv[i] = c;
m[r].push_back({c, i});
}
for (auto &[r, v] : m) sort(v.begin(), v.end());
for (int i = 0; i < nums; i++){
int r = rv[i], c = cv[i];
if (!m.count(r + 1)) nxt[i][0] = -1;
else{
auto it = lower_bound(m[r + 1].begin(), m[r + 1].end(), make_pair(c, -1));
if (it == m[r + 1].end()) nxt[i][0] = -1;
else nxt[i][0] = it->second;
}
}
for (int k = 1; k <= 19; k++)
for (int i = 0; i < nums; i++){
if (nxt[i][k - 1] == -1) nxt[i][k] = -1;
else nxt[i][k] = nxt[nxt[i][k - 1]][k - 1];
}
int queries; cin >> queries;
while (queries--) cout << (solve() ? "Yes" : "No") << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
5 ms |
4956 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
4 ms |
4700 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
22432 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
171 ms |
22604 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
119 ms |
21536 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
139 ms |
22584 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
204 ms |
32108 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
190 ms |
31988 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
243 ms |
32176 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
295 ms |
32596 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
263 ms |
32600 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
353 ms |
38388 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4956 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
4956 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
7 ms |
5468 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
4956 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
8 ms |
5192 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
4956 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
524 ms |
39580 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
382 ms |
34844 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
214 ms |
32336 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
758 ms |
51780 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
415 ms |
38684 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
222 ms |
32092 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
247 ms |
32232 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
197 ms |
31932 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
523 ms |
38584 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
536 ms |
38896 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
612 ms |
44492 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
174 ms |
31676 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
179 ms |
32200 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
267 ms |
32708 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
178 ms |
31772 KB |
200000 token(s): yes count is 129674, no count is 70326 |