# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369946 | A_D | Trampoline (info1cup20_trampoline) | C++14 | 485 ms | 35924 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=4e5+1000;
const int l=20;
int nxt[N][l];
vector<ii> vec;
main()
{
int r,c,n;
cin>>r>>c>>n;
for(int i=1;i<=n;i++){
int a,b;
scanf("%lld",&a);
scanf("%lld",&b);
vec.push_back({a,b});
}
sort(vec.begin(),vec.end());
int sz=vec.size();
for(int i=0;i<l;i++)nxt[sz][i]=sz;
for(int i=0;i<sz;i++){
int nx=lower_bound(vec.begin(),vec.end(),make_pair(vec[i].F+1,vec[i].S))-vec.begin();
if(nx!=sz&&vec[nx].F!=vec[i].F+1){
nx=sz;
}
nxt[i][0]=nx;
}
for(int j=1;j<l;j++){
for(int i=0;i<sz;i++){
nxt[i][j]=nxt[nxt[i][j-1]][j-1];
}
}
vec.push_back({1e10,1e10});
// for(int i=0;i<vec.size();i++)cout<<i<<" "<<vec[i].F<<" "<<vec[i].S<<endl;
// cout<<endl;
/*for(int i=0;i<sz;i++){
for(int j=0;j<l;j++){
cout<<nxt[i][j]<<" ";
}
cout<<endl;
}*/
int t;
cin>>t;
while(t--){
int x1,x2,y1,y2;
scanf("%lld",&x1);
scanf("%lld",&y1);
scanf("%lld",&x2);
scanf("%lld",&y2);
if(y2<y1||x2<x1){
// cout<<1;
printf("No\n");
continue;
}
if(x1==x2){
printf("Yes\n");
continue;
}
int i=lower_bound(vec.begin(),vec.end(),make_pair(x1,y1))-vec.begin();
for(int j=l-1;j>=0;j--){
if(((x2-x1-1)&(1<<j))){
if(i != sz) i = nxt[i][j];
}
}
// cout<<i<<endl;
int l=vec[i].S;
if(vec[i].S<=y2){
printf("Yes\n");
continue;
}
int r=nxt[i][0];
r=vec[r].S;
// cout<<i<<endl;
if(l<=y2&&y2<=r){
printf("Yes\n");
continue;
}
printf("No\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |