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>
using namespace std;
#define N 400005
int a[N],b[N],c[N],d[N];
long long l,r,ans=1e18;
vector<int> v;
class tree{
public:
vector<long long> t;
tree():t(4*N,1e18){}
void update(int x,int l,int r,int i,long long val){
if(l>c[i]||r<c[i])return ;
if(l==r){
t[x]=min(t[x],val);
return ;
}
int mid=(l+r)/2;
update(x*2,l,mid,i,val);
update(x*2+1,mid+1,r,i,val);
t[x]=min(t[x*2],t[x*2+1]);
}
long long sol(int x,int l,int r,int i){
if(l>b[i]||a[i]>r)return 1e18;
if(a[i]<=l&&r<=b[i])return t[x];
int mid=(l+r)/2;
return min(sol(x*2,l,mid,i),sol(x*2+1,mid+1,r,i));
}
}t1,t2;
int main(){
int n,m,i;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
v.push_back(a[i]);
v.push_back(b[i]);
v.push_back(c[i]);
}
v.push_back(-1);
v.push_back(1);
v.push_back(m);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(i=1;i<=n;i++){
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
b[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin();
c[i]=lower_bound(v.begin(),v.end(),c[i])-v.begin();
if(a[i]!=1)l=t1.sol(1,1,v.size()-1,i);
else l=0;
if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
else r=0;
ans=min(ans,l+r+d[i]);
t1.update(1,1,v.size()-1,i,l+d[i]);
t2.update(1,1,v.size()-1,i,r+d[i]);
}
if(ans!=1e18)printf("%lld",ans);
else printf("-1");
return 0;
}
Compilation message (stderr)
pinball.cpp: In function 'int main()':
pinball.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(b[i]!=v.size()-1)r=t2.sol(1,1,v.size()-1,i);
| ~~~~^~~~~~~~~~~~
pinball.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
pinball.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |