#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int r, c, n; cin>>r>>c>>n;
vector<ar<int, 2>> t(n);
for(int i=0;i<n;i++) cin>>t[i][0]>>t[i][1];
sort(t.begin(), t.end());
vector<vector<int>> in(n, vector<int>(20, -1));
map<int, vector<ar<int, 2>>> mm;
for(int i=0;i<n;i++){
mm[t[i][0]].push_back({t[i][1], i});
}
for(auto& [x, v] : mm) sort(v.begin(), v.end());
//~ for(int i=0;i<n;i++){
//~ cout<<t[i][0]<<" "<<t[i][1];
//~ cout<<"\n";
//~ } cout<<"\n";
for(int i=n-1;~i;i--){
if(mm.count(t[i][0] + 1)){
auto& v = mm[t[i][0] + 1];
auto it = lower_bound(v.begin(), v.end(), (ar<int, 2>){t[i][1], -1});
//~ for(auto x : v) cout<<x[0]<<" "<<x[1]<<"\n";
if(it != v.end()){
in[i][0] = (*it)[1];
}
}
for(int j=1;j<20;j++){
if(in[i][j-1] == -1) continue;
in[i][j] = in[in[i][j-1]][j-1];
}
}
int m; cin>>m;
for(int j=0;j<m;j++){
ar<int, 2> a, b; cin>>a[0]>>a[1]>>b[0]>>b[1];
if(b[0] < a[0] || b[1] < a[1]){
cout<<"No\n";
continue;
} if(a[0] == b[0]){
cout<<"Yes\n";
continue;
}
int d = b[0] - a[0] - 1;
if(d > 1e6) { cout<<"No\n"; continue; }
auto& v = mm[a[0]];
auto it = lower_bound(v.begin(), v.end(), (ar<int, 2>){a[1], -1});
if(it == v.end()){
cout<<"No\n";
continue;
}
int i = (*it)[1];
for(int j=19;~j;j--){
if((d >> j & 1) && ~i){
i = in[i][j];
}
}
if(~i && t[i][1] <= b[1]){
cout<<"Yes\n";
} else {
cout<<"No\n";
}
}
}
Compilation message
trampoline.cpp: In function 'int main()':
trampoline.cpp:20:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | for(auto& [x, v] : mm) sort(v.begin(), v.end());
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2380 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
7 ms |
2624 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
4 ms |
2000 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
47812 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
113 ms |
49608 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
112 ms |
48192 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
112 ms |
49528 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
235 ms |
47464 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
225 ms |
47124 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
219 ms |
46656 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
232 ms |
47848 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
231 ms |
47736 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
314 ms |
53500 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1484 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
1484 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
6 ms |
1868 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
1484 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
8 ms |
1612 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
1484 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
506 ms |
54624 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
391 ms |
49400 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
255 ms |
46628 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
666 ms |
65256 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
371 ms |
53276 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
266 ms |
47412 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
266 ms |
47456 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
252 ms |
46516 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
482 ms |
53372 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
505 ms |
53444 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
576 ms |
58948 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
221 ms |
47600 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
224 ms |
47340 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
308 ms |
54176 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
251 ms |
59216 KB |
200000 token(s): yes count is 129674, no count is 70326 |