#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;
template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }
const int N = 2e5 + 42, L = 18;
const int inf = 1e9 + 42;
int solve(){
int r, c, n;
cin >> r >> c >> n;
vec <pii> a(n);
map <pii, int> id;
map <int, vec <int>> v;
vec <int> xs(n);
for (int i = 0; i < n; ++i){
auto &[x, y] = a[i];
cin >> x >> y;
id[{x, y}] = i;
v[x].push_back(y);
xs[i] = x;
}
for (auto &[x, c]: v) sort(all(c));
auto nxt = [&](int x, int y){
if (v[x].empty()) return -1;
auto it = lower_bound(all(v[x]), y);
return it == v[x].end() ? -1 : id[mpp(x, *it)];
};
vec <vec <int>> g(n);
for (int i = 0; i < n; ++i){
auto [x, y] = a[i];
if (~nxt(x, y + 1)){
g[i].push_back(nxt(x, y + 1));
}
if (~nxt(x + 1, y)){
g[i].push_back(nxt(x + 1, y));
}
}
vec <vec <int>> go(n, vec <int> (L, -1));
auto mrg = [&](int i, int j){
if (!~i || !~j){
return ~i ? i : j;
}
return a[i].se < a[j].se ? i : j;
};
sort(rall(xs));
for (auto &x: xs){
for (int pt = sz(v[x]) - 1; ~pt; --pt){
int y = v[x][pt];
int u = id[{x, y}];
for (auto &v: g[u]){
auto [nx, ny] = a[v];
if (x == nx){
for (int l = 0; l < L; ++l){
go[u][l] = go[v][l];
}
}
else{
go[u][0] = mrg(go[u][0], v);
int cv = go[v][0];
for (int l = 1; l < L; ++l){
if (!~cv) break;
go[u][l] = cv;
cv = go[cv][l];
}
}
}
}
}
int q; cin >> q;
while(q--){
int sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
if (tx < sx || ty < sy){
cout << "No\n";
continue;
}
if (sx == tx){
cout << "Yes\n";
continue;
}
int i = nxt(sx, sy);
int dst = tx - sx - 1;
if (dst >= n){
cout << "No\n";
return 0;
}
for (int l = 0; l < L; ++l){
if (!~i) break;
if (dst >> l & 1){
i = go[i][l];
}
}
cout << (!~i || a[i].se > ty? "No\n" : "Yes\n");
}
return 0;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tst = 1; //cin >> tst;
while(tst--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
2388 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
88 ms |
2704 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
38 ms |
2004 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2083 ms |
48116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2066 ms |
47292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
105 ms |
1492 KB |
Answer contains longer sequence [length = 5000], but output contains 104 elements |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1683 ms |
56100 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
1700 ms |
50396 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Execution timed out |
2081 ms |
47412 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |