Submission #870107

#TimeUsernameProblemLanguageResultExecution timeMemory
870107imarnPinball (JOI14_pinball)C++14
0 / 100
2 ms10844 KiB
#include<bits/stdc++.h> #define f first #define s second #define ll long long #define pb push_back #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() using namespace std; const int N=3e5+5; ll dr[100001]{0},dl[100001]{0}; struct segment{ ll t[2*N]; void build(){ for(int i=0;i<2*N;i++)t[i]=1e17; } void upd(int i,ll amt,int sz){ i+=sz;t[i]=min(t[i],amt); for(i>>=1;i;i>>=1){ t[i]=min(t[2*i],t[2*i+1]); } } ll qr(int l,int r,int sz,ll res=1e17){ for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){ if(l&1)res=min(res,t[l++]); if(r&1)res=min(res,t[--r]); }return res; } }tl,tr; int main(){ int m,n;cin>>m>>n;tl.build();tr.build(); int a[m],b[m],c[m],d[m]; for(int i=0;i<m;i++)cin>>a[i]>>b[i]>>c[i]>>d[i]; vector<int>co; for(int i=0;i<m;i++)co.pb(a[i]),co.pb(b[i]),co.pb(c[i]); sort(co.begin(),co.end()); int M=3*m;ll ans=1e17; for(int i=0;i<m;i++){ dl[i]=dr[i]=1e17; ll mnl,mnr;mnl=mnr=1e17; if(a[i]==1)dl[i]=d[i],mnl=0; if(b[i]==n)dr[i]=d[i],mnr=0; a[i]=lower_bound(all(co),a[i])-co.begin(); b[i]=lower_bound(all(co),b[i])-co.begin(); c[i]=lower_bound(all(co),c[i])-co.begin(); ll le=tl.qr(a[i],b[i]+1,M); ll re=tr.qr(a[i],b[i]+1,M); dl[i]=min(dl[i],le+d[i]); dr[i]=min(dr[i],re+d[i]); mnl=min(mnl,le);mnr=min(mnr,re); tl.upd(c[i],dl[i],M); tr.upd(c[i],dr[i],M); ans=min(ans,mnl+mnr+d[i]); }cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...