#include <bits/stdc++.h>
#define pb emplace_back
#define All(x) x.begin(), x.end()
#define pii pair<int,int>
#define ff first
#define ss second
#define y1 y_1
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 200000;
const int L = 20;
int N, R, C, T;
pii pts[MAXN+1];
int x1, y1, x2, y2;
map <int, vector<pii>> arr;
int anc[MAXN+1][L];
void build() {
for (int i = 1; i <= N; i++) {
auto [x, y] = pts[i];
arr[x].pb(y, i);
}
for (auto &[x, v] : arr) {
sort(All(v));
}
for (int i = 1; i <= N; i++) {
auto [x, y] = pts[i];
if (arr[x-1].size()) {
auto it = upper_bound(All(arr[x-1]), pii(y, N+1));
if (it != arr[x-1].begin()) {
anc[i][0] = prev(it)->ss;
}
}
}
for (int i = 1; i < L; i++) {
for (int j = 1; j <= N; j++) {
anc[j][i] = anc[anc[j][i-1]][i-1];
}
}
}
bool solve(int x1, int y1, int x2, int y2) {
if (x1 == x2 && y1 <= y2) return true;
if (y1 > y2 || x1 > x2) return false;
if (!arr[x2-1].size()) return false;
auto it = upper_bound(All(arr[x2-1]), pii(y2, N+1));
if (it == arr[x2-1].begin()) return false;
int now = prev(it)->ss;
int K = x2 - x1 - 1;
for (int i = 1; i <= K; i *= 2) {
if (i & K) now = anc[now][__lg(i)];
}
assert(!now || pts[now].ff == x1);
return now && pts[now].ss >= y1;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> R >> C >> N;
for (int i = 1; i <= N; i++) {
auto &[x, y] = pts[i];
cin >> x >> y;
}
build();
cin >> T;
for (int i = 1; i <= T; i++) {
cin >> x1 >> y1 >> x2 >> y2;
cout << (solve(x1, y1, x2, y2) ? "Yes" : "No") << '\n';
}
}
Compilation message
trampoline.cpp: In function 'void build()':
trampoline.cpp:24:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | auto [x, y] = pts[i];
| ^
trampoline.cpp:27:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for (auto &[x, v] : arr) {
| ^
trampoline.cpp:31:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | auto [x, y] = pts[i];
| ^
trampoline.cpp: In function 'int main()':
trampoline.cpp:65:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 | auto &[x, y] = pts[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1232 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
8 ms |
1356 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
972 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
20748 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
212 ms |
20612 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
191 ms |
19864 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
208 ms |
20548 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
20304 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
295 ms |
20176 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
343 ms |
20356 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
399 ms |
21004 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
397 ms |
20932 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
704 ms |
26752 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
844 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
7 ms |
844 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
10 ms |
1612 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
6 ms |
844 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
9 ms |
972 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
7 ms |
844 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
862 ms |
28004 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
640 ms |
22936 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Runtime error |
181 ms |
39960 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |