#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pt;
int r, c, n, t;
const int maxn = 2e5+5;
const ll inf = 1e9+5;
map<int, vector<pair<int, int>>> mp;
int dd[maxn];
int sp[20][maxn];
void build(){
for(int i = 1; i < 20; i++){
for(int j = 1; j <= n; j++){
sp[i][j] = sp[i-1][sp[i-1][j]];
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c >> n;
for(int i = 1; i <= n; i++){
int a, b;
cin >> a >> b;
mp[a].push_back({b, i});
dd[i]=b;
}
for(auto it = mp.begin(); it != mp.end(); it++){
sort(it->s.begin(), it->s.end());
}
for(auto v: mp){
for(auto x: v.s){
int pos = lower_bound(mp[v.f+1].begin(), mp[v.f+1].end(), make_pair(x.f, 0))-mp[v.f+1].begin();
if(pos < mp[v.f+1].size())sp[0][x.s] = mp[v.f+1][pos].s;
}
}
build();
cin >> t;
while(t--){
int xs, ys, xt, yt;
cin >> xs >> ys >> xt >> yt;
if(ys > yt || xs > xt || xt - xs > n){
cout << "No\n";
continue;
}
if(xs == xt){
cout << "Yes\n";
continue;
}
int pos = lower_bound(mp[xs].begin(), mp[xs].end(), make_pair(ys, 0))-mp[xs].begin();
if(pos == mp[xs].size())cout << "No\n";
else{
int crr = mp[xs][pos].s;
for(int i = 0; i < 20; i++){
if((1<<i)&(xt-xs-1))crr = sp[i][crr];
}
if(crr && dd[crr] <= yt)cout << "Yes\n";
else cout << "No\n";
}
}
}
Compilation message
trampoline.cpp: In function 'int main()':
trampoline.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(pos < mp[v.f+1].size())sp[0][x.s] = mp[v.f+1][pos].s;
| ~~~~^~~~~~~~~~~~~~~~~~
trampoline.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | if(pos == mp[xs].size())cout << "No\n";
| ~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1236 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
1348 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
1108 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
19840 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
87 ms |
19804 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
76 ms |
19044 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
85 ms |
19752 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
19944 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
186 ms |
19840 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
192 ms |
19668 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
237 ms |
20180 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
236 ms |
20220 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
419 ms |
26036 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
852 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
852 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
8 ms |
1784 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
4 ms |
852 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
7 ms |
980 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
852 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
27296 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
410 ms |
22232 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
203 ms |
19744 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
664 ms |
39356 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
374 ms |
26452 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
211 ms |
20048 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
217 ms |
20196 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
203 ms |
19600 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
514 ms |
26096 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
566 ms |
26348 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
606 ms |
32108 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
182 ms |
19564 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
176 ms |
19572 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
263 ms |
20120 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
188 ms |
19568 KB |
200000 token(s): yes count is 129674, no count is 70326 |