#include <bits/stdc++.h>
using namespace std;
#define int long long
using ii = pair<int,int>;
vector<int> adj[200005];
int pa[200005], h[200005], j[200005];
void dfs(int x) {
for(auto i: adj[x]) {
h[i] = h[x] + 1;
j[i] = (h[j[j[x]]]+h[x]==(h[j[x]]<<1)?j[j[x]]:x);
dfs(i);
}
}
int lift(int x, int t) {
while(h[x]>t) x=(h[j[x]]<t?pa[x]:j[x]);
return x;
}
main() {
int r, c, n; cin >> r >> c >> n;
vector<ii> v;
for(int x,y,i=0;i<n;i++) {
cin >> x >> y;
v.push_back({x,y});
}
sort(v.begin(),v.end());
for(int i=0;i<n;i++) {
auto [x,y] = v[i];
auto it = lower_bound(v.begin(),v.end(),ii(x+1,y));
if(it==v.end()||(*it).first>x+1) pa[i]=n;
else pa[i]=it-v.begin();
adj[pa[i]].push_back(i);
}
j[n] = n; dfs(n);
int t; cin >> t;
for(int x1,y1,x2,y2;t--;) {
cin >> x1 >> y1 >> x2 >> y2;
if(x1==x2) {
cout << (y1<=y2?"Yes\n":"No\n");
continue;
}
if(x1>x2) {
cout << "No\n";
continue;
}
auto it = lower_bound(v.begin(),v.end(),ii(x1,y1));
if(it==v.end()||(*it).first>x1) {
cout << "No\n";
continue;
}
int green = it - v.begin();
if(h[green]<x2-x1-1) {
cout << "No\n";
continue;
}
int dest = lift(green,h[green]-(x2-x1-1));
cout << (dest!=n && v[dest].first==x2-1 && v[dest].second<=y2 ? "Yes\n" : "No\n");
}
}
Compilation message
trampoline.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7892 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
6 ms |
8148 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
4 ms |
7864 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
17844 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
113 ms |
17800 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
85 ms |
19848 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
106 ms |
18100 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
508 ms |
26296 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
511 ms |
28344 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
528 ms |
28856 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
519 ms |
29620 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
541 ms |
29624 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
576 ms |
32956 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8028 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
20 ms |
8028 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
17 ms |
8024 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
16 ms |
8028 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
16 ms |
8028 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
16 ms |
8188 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
595 ms |
27932 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
610 ms |
25888 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
570 ms |
27316 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
602 ms |
41396 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
541 ms |
33120 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
593 ms |
28856 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
560 ms |
29372 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
499 ms |
29884 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
602 ms |
32188 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
604 ms |
32696 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
648 ms |
36280 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
661 ms |
27920 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
592 ms |
27720 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
628 ms |
30320 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
631 ms |
29368 KB |
200000 token(s): yes count is 129674, no count is 70326 |