#include <bits/stdc++.h>
using namespace std;
int r, c;
const int LG = 20;
vector<pair<int, int>> a;
vector<vector<int>> jmps;
void build_jumps(){
jmps.assign(a.size(), vector<int> (20));
for (int i=a.size()-1; i>=0; i--){
vector<pair<int, int>>::iterator it =
lower_bound(a.begin(), a.end(), make_pair(a[i].first+1, a[i].second));
if (it == a.end() || it->first != a[i].first + 1) it = a.end();
int ptr = it - a.begin();
jmps[i][0] = ptr;
for (int p=1; p<LG; p++){
int dn = jmps[i][p-1];
if (dn == a.size()) jmps[i][p] = a.size();
else jmps[i][p] = jmps[dn][p-1];
}
}
}
int jump(int ptr, int step){
if (ptr == a.size()) return a.size();
if (step > 1000000) return a.size();
if (step == 0) return ptr;
int lg2 = 31 - __builtin_clz(step);
return jump(jmps[ptr][lg2], step - (1<<lg2));
}
bool solve(int xf, int yf, int xt, int yt){
if (yt < yf || xt < xf)
return false;
if (xf == xt)
return true;
vector<pair<int, int>>::iterator it =
lower_bound(a.begin(), a.end(), make_pair(xf, yf));
if (it == a.end() || it->first != xf)
return false;
int ptrstart = it - a.begin();
int dest = jump(ptrstart, xt - xf - 1);
if (dest == a.size() || a[dest].second > yt) return false;
return true;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> r >> c;
int n; cin >> n;
a.resize(n);
for (int i=0; i<n; i++)
cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
build_jumps();
int t; cin >> t;
while (t--){
int xf, yf, xt, yt; cin >> xf >> yf >> xt >> yt;
if (solve(xf, yf, xt, yt))
cout << "Yes\n";
else
cout << "No\n";
}
}
Compilation message
trampoline.cpp: In function 'void build_jumps()':
trampoline.cpp:17: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]
17 | if (dn == a.size()) jmps[i][p] = a.size();
| ~~~^~~~~~~~~~~
trampoline.cpp: In function 'int jump(int, int)':
trampoline.cpp:23:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if (ptr == a.size()) return a.size();
| ~~~~^~~~~~~~~~~
trampoline.cpp: In function 'bool solve(int, int, int, int)':
trampoline.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if (dest == a.size() || a[dest].second > yt) return false;
| ~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1476 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
5 ms |
1620 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
4 ms |
1196 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
27216 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
82 ms |
27236 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
107 ms |
26836 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
116 ms |
27204 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
214 ms |
37712 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
223 ms |
37700 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
202 ms |
37660 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
235 ms |
37696 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
221 ms |
37720 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
276 ms |
37544 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1252 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
12 ms |
1236 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
6 ms |
1240 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
9 ms |
1236 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
11 ms |
1236 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
10 ms |
1248 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
393 ms |
37728 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
369 ms |
37704 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
218 ms |
37708 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
498 ms |
37656 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
275 ms |
37612 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
241 ms |
37908 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
231 ms |
37844 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
248 ms |
37896 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
356 ms |
37660 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
431 ms |
37724 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
445 ms |
37704 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
202 ms |
37728 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
243 ms |
37716 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
284 ms |
37828 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
210 ms |
37812 KB |
200000 token(s): yes count is 129674, no count is 70326 |