#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// author: aykhn
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define TC int t; cin >> t; while (t--) _();
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_setp tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mpr make_pair
#define eb emplace_back
#define new int32_t
#define pb push_back
#define ts to_string
#define int ll
#define fi first
#define se second
#define ins insert
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
int n, R, C;
vector<int> adj[200001];
pii a[200001];
int used[200001];
int par[20][200001];
void dfs(int a)
{
used[a] = 1;
for (int i = 0; i < adj[a].size(); i++)
{
if (!used[adj[a][i]])
{
par[0][adj[a][i]] = a;
dfs(adj[a][i]);
}
}
}
new main()
{
OPT;
cin >> R >> C >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].fi >> a[i].se;
}
int cnt = 0;
sort(a, a + n);
for (int i = 0; i < n; i++)
{
int x = lower_bound(a, a + n, mpr(a[i].fi + 1, a[i].se)) - a;
if (x == n || a[x].fi != a[i].fi + 1) continue;
adj[x].pb(i);
}
for (int i = n - 1; i >= 0; i--)
{
if (!used[i]) dfs(i);
}
for (int i = 1; i < 20; i++)
{
for (int j = 1; j <= n; j++)
{
par[i][j] = par[i - 1][par[i - 1][j]];
}
}
int t;
cin >> t;
while (t--)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2 && y1 <= y2)
{
cout << "Yes" << endl;
continue;
}
if (x1 > x2 || y1 > y2)
{
cout << "No" << endl;
continue;
}
int node = lower_bound(a, a + n, mpr(x1, y1)) - a;
if (node == n || a[node].fi != x1)
{
cout << "No" << endl;
continue;
}
int dif = x2 - x1 - 1;
for (int i = 19; i >= 0; i--)
{
if ((1 << i) <= dif)
{
node = par[i][node];
dif -= (1 << i);
}
}
if (!node || a[node].fi + 1 != x2 || a[node].se > y2) cout << "No" << endl;
else cout << "Yes" << endl;
}
}
Compilation message
trampoline.cpp: In function 'void dfs(ll)':
trampoline.cpp:40:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < adj[a].size(); i++)
| ~~^~~~~~~~~~~~~~~
trampoline.cpp: In function 'int32_t main()':
trampoline.cpp:61:9: warning: unused variable 'cnt' [-Wunused-variable]
61 | int cnt = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6964 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
7 ms |
7252 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
6612 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
46492 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
84 ms |
46504 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
104 ms |
47948 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
86 ms |
46764 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
369 ms |
55900 KB |
expected YES, found NO [13193rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
6484 KB |
expected YES, found NO [2629th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
61620 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Incorrect |
477 ms |
58532 KB |
expected YES, found NO [17204th token] |
3 |
Halted |
0 ms |
0 KB |
- |