#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
#define LOCALIO "C:/Users/admin/Documents/Code/"
vector <pll> tram;
ll to[200005][20];
void answer(ll a)
{
if (a) cout << "Yes\n";
else cout << "No\n";
}
int main()
{
#ifdef LOCAL
freopen( LOCALIO "input.txt","r",stdin) ;
freopen( LOCALIO "output.txt","w",stdout) ;
#endif
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
// freopen("FIBONACCI.inp","r",stdin);
// freopen("FIBONACCI.out","w",stdout);
ll R, C, n; cin >> R >> C >> n;
for (ll i=1; i<=n; i++)
{
ll r, c; cin >> r >> c;
tram.pb({r, c});
}
sort(tram.begin(), tram.end());
for (ll i=0; i<n; i++)
{
ll r=tram[i].fi, c=tram[i].se;
auto ptr=lower_bound(tram.begin(), tram.end(), mp(r+1, c));
if (ptr==tram.end())
{
to[i][0]=-1;
continue;
}
pll ptr1=*ptr; ll r1=ptr1.fi, c1=ptr1.se;
if (r1!=r+1)
{
to[i][0]=-1;
continue;
}
to[i][0]=ptr-tram.begin();
}
// for (ll i=0; i<n; i++)
// cout << i << " " << to[i][0] << "\n";
for (ll l=1; l<20; l++)
{
for (ll i=0; i<n; i++)
{
ll t=to[i][l-1];
if (t==-1)
{
to[i][l]=-1;
continue;
}
to[i][l]=to[t][l-1];
}
}
ll t; cin >> t;
while(t--)
{
ll xa, ya, xb, yb;
cin>>xa>>ya>>xb>>yb;
if (xa==xb)
{
answer(yb>=ya);
continue;
}
ll jump=xb-xa-1, f=lower_bound(tram.begin(), tram.end(), mp(xa, ya))-tram.begin(), bit=0;
if (f>=tram.size() || tram[f].fi!=xa)
{
answer(0);
continue;
}
while (f!=-1 && jump)
{
if (jump&1)
f=to[f][bit];
bit++; jump>>=1;
}
if (f==-1 || tram[f].se>yb)
answer(0);
else answer(1);
}
}
Compilation message
trampoline.cpp: In function 'int main()':
trampoline.cpp:49:39: warning: unused variable 'c1' [-Wunused-variable]
49 | pll ptr1=*ptr; ll r1=ptr1.fi, c1=ptr1.se;
| ^~
trampoline.cpp:83:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | if (f>=tram.size() || tram[f].fi!=xa)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1880 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
2136 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
1620 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
34876 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
122 ms |
34844 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
105 ms |
34888 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
115 ms |
34892 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
35512 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
217 ms |
35608 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
223 ms |
35536 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
224 ms |
35580 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
232 ms |
35476 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
232 ms |
35488 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
5 ms |
1236 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
4 ms |
1236 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
1236 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
5 ms |
1236 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
1328 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
394 ms |
35592 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
339 ms |
35644 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
283 ms |
35712 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
399 ms |
35616 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
300 ms |
35560 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
258 ms |
35616 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
271 ms |
35544 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
309 ms |
35544 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
397 ms |
35636 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
405 ms |
35668 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
444 ms |
35592 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
271 ms |
35600 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
325 ms |
35576 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
319 ms |
35684 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
244 ms |
35636 KB |
200000 token(s): yes count is 129674, no count is 70326 |