#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];
}
}
//~ for(int j=0;j<5;j++){
//~ for(int i=0;i<n;i++){
//~ cout<<in[i][j]<<" ";
//~ } cout<<"\n";
//~ }
int m; cin>>m;
while(m--){
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 > n) { 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 = 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 |
Runtime error |
6 ms |
4672 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
171 ms |
96908 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
47640 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
251 ms |
47392 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
239 ms |
46884 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
243 ms |
47940 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
296 ms |
47916 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
357 ms |
53580 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1740 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
9 ms |
1744 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
2124 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
11 ms |
1740 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
7 ms |
1780 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
6 ms |
1740 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
570 ms |
54688 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
402 ms |
49720 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
279 ms |
46976 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
736 ms |
65560 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
438 ms |
53532 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
314 ms |
47944 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
305 ms |
47704 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
265 ms |
46772 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
508 ms |
53592 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
556 ms |
53552 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
623 ms |
59360 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
228 ms |
47848 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
261 ms |
47568 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Runtime error |
186 ms |
95356 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |