#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[200005];
pii a[200005];
int used[200005];
int par[20][200005];
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 = 1; i <= n; i++)
{
cin >> a[i].fi >> a[i].se;
}
int cnt = 0;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
{
int x = lower_bound(a + 1, a + n + 1, mpr(a[i].fi + 1, a[i].se)) - a;
if (x == n + 1 || a[x].fi != a[i].fi + 1) continue;
adj[x].pb(i);
}
for (int i = n; i >= 1; 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 + 1, a + n + 1, mpr(x1, y1)) - a;
if (node == n + 1 || a[node].fi != x1)
{
cout << "No" << endl;
continue;
}
y1 = a[node].se;
if (y1 > y2)
{
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 |
6868 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
6 ms |
7124 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
6484 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
44716 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
85 ms |
44744 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
86 ms |
46420 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
89 ms |
44872 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
44140 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
397 ms |
56528 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
363 ms |
57080 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
380 ms |
57936 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
390 ms |
57636 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
377 ms |
60236 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6100 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
14 ms |
6504 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
11 ms |
6356 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
11 ms |
6484 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
12 ms |
6544 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
11 ms |
6356 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
450 ms |
50000 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
433 ms |
46940 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
393 ms |
57112 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
465 ms |
69140 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
388 ms |
60372 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
379 ms |
56592 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
400 ms |
56608 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
421 ms |
57164 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
468 ms |
60364 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
455 ms |
60832 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
456 ms |
64240 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
360 ms |
55932 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
357 ms |
55880 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
414 ms |
57884 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
374 ms |
57152 KB |
200000 token(s): yes count is 129674, no count is 70326 |