#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true; return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true; return false;
}
using ll = long long;
using ld = long double;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); }
template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); }
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
int R, C, N;
cin >> R >> C >> N;
int sizeBoard = max(R, C);
vector<pair<int, int>> cells;
auto encode = [&](int r, int c) -> long long{
return 1LL * r * sizeBoard + c;
};
auto decode = [&](long long code){
return make_pair(code / sizeBoard, code % sizeBoard);
};
vector<long long> codes;
for(int i = 0; i < N; ++i){
int x, y;
cin >> x >> y;
--x, --y;
codes.emplace_back(encode(x, y));
}
sort(all(codes));
compact(codes);
codes.emplace_back((long long)2e18);
N = (int)codes.size();
int L = 32 - __builtin_clz(N);
vector<vector<int>> up(L, vector<int>(N, N - 1));
for(int i = 0; i < N - 1; ++i){
int r, c;
tie(r, c) = decode(codes[i]);
long long next_code = encode(r + 1, c);
int pos = lower_bound(all(codes) + i, next_code) - codes.begin();
if(pos >= N - 1) continue;
int nr, nc;
tie(nr, nc) = decode(codes[pos]);
if(r == nr - 1 && c <= nc) {
up[0][i] = pos;
}
}
for(int i = 1; (1 << i) <= N; ++i){
for(int j = 0; j < N; ++j){
up[i][j] = up[i - 1][up[i - 1][j]];
}
}
int Q;
cin >> Q;
while(Q--){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1, --x2, --y2;
if(x1 > x2 || y1 > y2 || (x2 - x1 - 1 > N)){
cout << "No\n";
continue;
}
if(x1 == x2){
cout << "Yes\n";
continue;
}
int pos = lower_bound(all(codes), encode(x1, y1)) - codes.begin();
if(pos == N - 1){
cout << "No\n";
continue;
}
int r, c;
tie(r, c) = decode(codes[pos]);
if(r != x1){
cout << "No\n";
continue;
}
int k = x2 - x1 - 1;
for(int i = 0; i < L; ++i){
if(k >> i & 1){
pos = up[i][pos];
}
}
if(pos == N - 1){
cout << "No\n";
continue;
}
tie(r, c) = decode(codes[pos]);
if(r != x2 - 1 || c > y2){
cout << "No\n";
} else{
cout << "Yes\n";
}
}
return 0;
}
Compilation message
trampoline.cpp: In function 'bool minimize(T&, const T&)':
trampoline.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
15 | if(a > b) return a = b, true; return false;
| ^~
trampoline.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
15 | if(a > b) return a = b, true; return false;
| ^~~~~~
trampoline.cpp: In function 'bool maximize(T&, const T&)':
trampoline.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
20 | if(a < b) return a = b, true; return false;
| ^~
trampoline.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
20 | if(a < b) return a = b, true; return false;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
848 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
3 ms |
1104 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
2 ms |
848 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
69 ms |
34760 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
71 ms |
34752 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
592 KB |
expected YES, found NO [10th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
18104 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
183 ms |
29628 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Runtime error |
83 ms |
38956 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |