This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |