#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(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 debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 200010, MAX_K = 19;
int R, C, n;
int nxt[MAX_K][MAX_N];
pair<int,int> a[MAX_N];
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> R >> C >> n;
for (int x, y, i = 0;i < n;++i) {
cin >> x >> y;
a[i] = {x, y};
}
sort(a, a+n);
// init
for (int i = n-1, j = n-1;i >= 0;--i) {
auto [x, y] = a[i];
while (j > 0 && a[j-1] >= make_pair(x+1, y))
--j;
auto [nx, ny] = a[j];
if (nx == x+1 && ny >= y)
nxt[0][i] = j;
else
nxt[0][i] = n;
DE(x, y, nx, ny);
}
nxt[0][n] = n;
for (int d = 1;d < MAX_K;++d)
for (int i = 0;i <= n;++i)
nxt[d][i] = nxt[d-1][ nxt[d-1][i] ];
int Q;
cin >> Q;
for (int x1, y1, x2, y2, i = 0;i < Q;++i) {
cin >> x1 >> y1 >> x2 >> y2;
int ind = lower_bound(a, a+n, make_pair(x1, y1)) - a;
auto [x, y] = a[ind];
DE(x1, y1, x, y, x2, y2);
if (x1 > x2 || y1 > y2) {
cout << "No\n";
continue;
}
if (x1 == x2) {
cout << "Yes\n";
continue;
}
if (ind == n || x != x1) {
cout << "No\n";
continue;
}
int d = x2 - x1 - 1;
for (int j = 0;j < MAX_K;++j)
if (d>>j&1) ind = nxt[j][ind];
tie(x, y) = a[ind];
DE(x, y);
if (ind == n || y > y2) {
cout << "No\n";
}
else {
assert(x == x2 - 1);
cout << "Yes\n";
}
}
}
Compilation message
trampoline.cpp: In function 'int32_t main()':
trampoline.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
trampoline.cpp:50:3: note: in expansion of macro 'DE'
50 | DE(x, y, nx, ny);
| ^~
trampoline.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
trampoline.cpp:69:3: note: in expansion of macro 'DE'
69 | DE(x1, y1, x, y, x2, y2);
| ^~
trampoline.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
trampoline.cpp:93:3: note: in expansion of macro 'DE'
93 | DE(x, y);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1152 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
1228 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
972 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
16744 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
75 ms |
16720 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
70 ms |
16708 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
74 ms |
16652 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
17396 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
207 ms |
17432 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
215 ms |
17392 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
218 ms |
17324 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
218 ms |
17344 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
224 ms |
17368 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
844 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
1100 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
6 ms |
1100 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
6 ms |
1100 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
6 ms |
1100 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
6 ms |
1108 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
368 ms |
17608 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
361 ms |
17476 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
248 ms |
29172 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
383 ms |
29048 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
275 ms |
29120 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
243 ms |
29132 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
260 ms |
29228 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
239 ms |
29120 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
358 ms |
29160 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
364 ms |
29048 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
378 ms |
29236 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
225 ms |
29228 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
227 ms |
29252 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
272 ms |
29124 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
226 ms |
29384 KB |
200000 token(s): yes count is 129674, no count is 70326 |