#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 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;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
3 ms |
840 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
34760 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
34752 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
764 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
76 ms |
34840 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |