Submission #707343

#TimeUsernameProblemLanguageResultExecution timeMemory
707343amirhoseinfar1385Pinball (JOI14_pinball)C++17
100 / 100
278 ms40408 KiB
#include<bits/stdc++.h> using namespace std; int n,m; long long inf=1e15,kaf=(1<<20); struct segment{ long long seg[(1<<21)]; segment(){ for(int i=0;i<(1<<21);i++){ seg[i]=inf; } } void upd(int i,long long w){ if(i==0){ return ; } seg[i]=min(seg[i],w); return upd((i>>1),w); } long long pors(int i,int l,int r,int tl,int tr){ if(l>r||l>tr||r<tl){ return inf; } if(l>=tl&&r<=tr){ return seg[i]; } int m=(l+r)>>1; long long ret=min(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr)); return ret; } }; segment seg1,seg2; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; long long res=inf; vector<pair<pair<int,int>,pair<int,int>>>allq(n); vector<int>allind; for(int i=0;i<n;i++){ cin>>allq[i].first.first>>allq[i].first.second>>allq[i].second.first>>allq[i].second.second; allind.push_back(allq[i].first.first); allind.push_back(allq[i].first.second); allind.push_back(allq[i].second.first); } allind.push_back(1); allind.push_back(m); sort(allind.begin(),allind.end()); allind.resize(unique(allind.begin(),allind.end())-allind.begin()); int p=lower_bound(allind.begin(),allind.end(),1)-allind.begin(); seg1.upd(kaf+p,0); p=lower_bound(allind.begin(),allind.end(),m)-allind.begin(); seg2.upd(kaf+p,0); for(int i=0;i<n;i++){ long long l,r,c,w; c=lower_bound(allind.begin(),allind.end(),allq[i].second.first)-allind.begin(); w=allq[i].second.second; l=lower_bound(allind.begin(),allind.end(),allq[i].first.first)-allind.begin(); r=lower_bound(allind.begin(),allind.end(),allq[i].first.second)-allind.begin(); //cin>>l>>r>>c>>w; long long fake=seg1.pors(1,0,kaf-1,l,r)+seg2.pors(1,0,kaf-1,l,r); fake+=w; res=min(fake,res); fake=seg1.pors(1,0,kaf-1,l,r); fake+=w; seg1.upd(kaf+c,fake); fake=seg2.pors(1,0,kaf-1,l,r); fake+=w; seg2.upd(kaf+c,fake); } if(res>=inf){ cout<<-1<<"\n"; } else{ cout<<res<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...