#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;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int R, C, N, T, r1, c1, r2, c2, a[200005], b[200005], anc[200005][25];
bool in[200005];
vector<int> adj[200005];
map<ii, int> _lab;
map<int, vector<int> > vec;
inline int lab(int a, int b) {
assert(_lab.find(mp(a, b)) != _lab.end());
return _lab[mp(a, b)];
}
void dfs(int n, int e = -1) {
anc[n][0] = e;
for (int i = 1; i <= 20; i++)
if (anc[n][i - 1] != -1) anc[n][i] = anc[anc[n][i - 1]][i - 1];
for (auto u : adj[n]) if (u != e) dfs(u, n);
}
main() {
memset(anc, -1, sizeof anc);
ios::sync_with_stdio(0);
cin.tie(0);
cin >> R >> C >> N;
for (int i = 1; i <= N; i++) {
cin >> a[i] >> b[i];
vec[a[i]].pb(b[i]);
_lab[mp(a[i], b[i])] = i;
}
for (auto &i : vec) {
sort(i.second.begin(), i.second.end());
for (int j : i.second) {
auto tmp = lower_bound(vec[i.first + 1].begin(), vec[i.first + 1].end(), j);
if (tmp != vec[i.first + 1].end()) {
adj[lab(i.first + 1, *tmp)].pb(lab(i.first, j));
in[lab(i.first, j)] = 1;
}
}
}
for (int i = 1; i <= N; i++) {
if (!in[i]) dfs(i);
}
cin >> T;
while (T--) {
cin >> r1 >> c1 >> r2 >> c2;
if (r1 > r2) cout << "No\n";
else if (r1 == r2) {
if (c1 <= c2) cout << "Yes\n";
else cout << "No\n";
} else {
auto tmp = lower_bound(vec[r1].begin(), vec[r1].end(), c1);
if (tmp != vec[r1].end()) {
int curr = lab(r1, *tmp), up = 0;
for (int i = 20; i >= 0; i--)
if (anc[curr][i] != -1 && up + (1 << i) < r2 - r1) {
curr = anc[curr][i];
up += (1 << i);
assert(a[curr] == r1 + up);
}
if (a[curr] == r2 - 1 && b[curr] <= c2) cout << "Yes\n";
else cout << "No\n";
} else cout << "No\n";
}
}
}
Compilation message
trampoline.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
45004 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
428 ms |
64916 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
841 ms |
63412 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
845 ms |
64252 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
905 ms |
64560 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
983 ms |
65360 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
949 ms |
65536 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
1230 ms |
71568 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
44620 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1272 ms |
73624 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |