Submission #798017

#TimeUsernameProblemLanguageResultExecution timeMemory
798017mrwangPinball (JOI14_pinball)C++14
100 / 100
199 ms15992 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<int,int> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=2e5; const ll inf=1e18; const ll mod=1e9+7; ll st[4*maxN]; ll n; void update(ll pos,ll val,ll id=1,ll l=1,ll r=n+2) { if(l==r) { st[id]=min(st[id],val); return; } ll mid=l+r>>1; if(pos<=mid) update(pos,val,id*2,l,mid); else update(pos,val,id*2+1,mid+1,r); st[id]=min(st[id*2],st[id*2+1]); } ll get(ll i,ll j,ll id=1,ll l=1,ll r=n+2) { if(j<l||r<i) return inf; if(i<=l&&r<=j) return st[id]; ll mid=l+r>>1; return min(get(i,j,id*2,l,mid),get(i,j,id*2+1,mid+1,r)); } ll dp[2][maxN],a[maxN],c[maxN],d[maxN],e[maxN],b[maxN]; void cal(ll x,ll t) { dp[t][0]=0; c[0]=x; fill(st,st+4*maxN,inf); for(int i=0;i<=n;i++) { if(i!=0) { dp[t][i]=inf; ll l,r; l=lower_bound(e+1,e+n+3,a[i])-e; r=upper_bound(e+1,e+n+3,b[i])-e-1; dp[t][i]=min(dp[t][i],get(l,r)+d[i]); } ll pos=lower_bound(e+1,e+n+3,c[i])-e; update(pos,dp[t][i]); } } ll m,sz=0; void solve() { cin >> n >> m; for(int i=1;i<=n;i++) cin >> a[i] >> b[i] >> c[i] >> d[i],e[++sz]=c[i]; e[n+1]=1; e[n+2]=m; sort(e+1,e+n+3); cal(1,0); cal(m,1); ll ans=inf; for(int i=1;i<=n;i++) { ans=min(ans,dp[0][i]+dp[1][i]-d[i]); } if(ans!=inf) cout << ans; else cout << -1; } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

Compilation message (stderr)

pinball.cpp: In function 'void update(ll, ll, ll, ll, ll)':
pinball.cpp:22:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     ll mid=l+r>>1;
      |            ~^~
pinball.cpp: In function 'll get(ll, ll, ll, ll, ll)':
pinball.cpp:31:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |     ll mid=l+r>>1;
      |            ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...