#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), 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 |
1096 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
2 ms |
864 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
18624 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
54 ms |
19084 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
55 ms |
18880 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
54 ms |
19136 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
17856 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
144 ms |
29632 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
143 ms |
29628 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
149 ms |
29632 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
152 ms |
29764 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
174 ms |
29528 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
848 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
4 ms |
1068 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
5 ms |
1272 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
4 ms |
1104 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
5 ms |
1016 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
4 ms |
1104 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
18012 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
171 ms |
18008 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
161 ms |
25536 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
217 ms |
29632 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
167 ms |
29632 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
146 ms |
29632 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
150 ms |
29632 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
155 ms |
29700 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
190 ms |
29508 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
190 ms |
29752 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
195 ms |
29632 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
150 ms |
29832 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
147 ms |
29760 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
183 ms |
29632 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
165 ms |
29640 KB |
200000 token(s): yes count is 129674, no count is 70326 |