#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;
bool dbg = 1;
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 <int> go(n, -1);
for (int i = 0; i < n; ++i){
auto [x, y] = a[i];
if (~nxt(x + 1, y)){
go[i] = nxt(x + 1, y);
}
else if (~nxt(x, y + 1)){
go[i] = nxt(x, y + 1);
}
}
vec <vec <int>> up(n, vec <int> (L, -1));
sort(all(xs));
xs.erase(unique(all(xs)), xs.end());
reverse(all(xs));
for (auto &x: xs){
for (int pt = sz(v[x]) - 1; ~pt; --pt){
int y = v[x][pt];
int u = id[{x, y}], v = go[u];
if (!~v) continue;
if (a[u].fi + 1 == a[v].fi){
up[u][0] = v;
int cv = up[v][0];
for (int l = 1; l < L; ++l){
if (!~cv) break;
up[u][l] = cv, cv = up[cv][l];
}
}
else up[u] = up[v];
}
}
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 u = nxt(sx, sy);
int dst = tx - sx - 1;
if (dst >= n){
cout << "No\n";
continue;
}
for (int l = 0; l < L; ++l){
if (!~u) break;
if (dst >> l & 1){
u = up[u][l];
}
}
cout << (!~u || a[u].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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1988 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
13 ms |
2132 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
9 ms |
1620 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
543 ms |
38032 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
531 ms |
39976 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
495 ms |
38992 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
513 ms |
40108 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
45632 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
615 ms |
49480 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
633 ms |
49600 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
792 ms |
50248 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
772 ms |
50076 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
1012 ms |
56084 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1236 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
9 ms |
1272 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
11 ms |
2156 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
9 ms |
1236 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
12 ms |
1364 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
7 ms |
1236 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1337 ms |
45972 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
1088 ms |
40780 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
646 ms |
45696 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
1459 ms |
70604 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
911 ms |
56996 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
722 ms |
49572 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
692 ms |
49588 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
654 ms |
49556 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
1269 ms |
56236 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
1273 ms |
56244 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
1416 ms |
63284 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
511 ms |
49596 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
547 ms |
49660 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
904 ms |
50124 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
590 ms |
49564 KB |
200000 token(s): yes count is 129674, no count is 70326 |