Submission #546349

#TimeUsernameProblemLanguageResultExecution timeMemory
546349krit3379Pinball (JOI14_pinball)C++17
0 / 100
4 ms6612 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 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,int pos,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,pos,val); update(x*2+1,mid+1,r,i,pos,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); 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,1,l+d[i]); t2.update(1,1,v.size()-1,i,n,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:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...