제출 #901397

#제출 시각아이디문제언어결과실행 시간메모리
901397abcvuitunggioShortcut (IOI16_shortcut)C++17
0 / 100
1 ms6492 KiB
#include "shortcut.h" #include <bits/stdc++.h> #define T pair <long long, long long> using namespace std; const long long INF=1e18; const int mxn=300001; long long s[mxn]; int d[mxn],id,idx[mxn],root[mxn],le[mxn*20],ri[mxn*20],order[mxn]; T st[mxn*20]; vector <long long> v; T operator +(T a, T b){ return {max(a.first,b.first),min(a.second,b.second)}; } int update(int node, int l, int r, int i){ id++; if (l==r){ st[id]={s[l]+d[l],s[l]-d[l]}; return id; } int cur=id,mid=(l+r)>>1; st[cur]=st[node]; le[cur]=le[node]; ri[cur]=ri[node]; if (mid<i) ri[cur]=update(ri[node],mid+1,r,i); else le[cur]=update(le[node],l,mid,i); st[cur]=st[le[cur]]+st[ri[cur]]; return cur; } T get(int node, int l, int r, int u, int v){ if (l>v||r<u||l>r||u>v||!node) return {-INF,INF}; if (l>=u&&r<=v) return st[node]; int mid=(l+r)>>1; return get(le[node],l,mid,u,v)+get(ri[node],mid+1,r,u,v); } long long find_shortcut(int n, vector <int> l, vector <int> D, int c){ long long lo=0,hi=INF,kq=-1; for (int i=0;i<n;i++) d[i]=D[i]; for (int i=1;i<n;i++){ s[i]=s[i-1]+l[i-1]; v.push_back(s[i]); } sort(v.begin(),v.end()); iota(idx,idx+n,0); iota(order,order+n,0); sort(idx,idx+n,[](int i, int j){return s[i]+d[i]>s[j]+d[j];}); sort(order,order+n,[](int i, int j){return s[i]-d[i]<s[j]-d[j];}); st[0]={-INF,INF}; for (int i=0;i<n;i++) root[i]=update((i?root[i-1]:0),0,n-1,idx[i]); while (lo<=hi){ long long mid=(lo+hi)>>1,ch=0,mnx=-INF,mxx=INF,mny=-INF,mxy=INF; int pos=0; for (int j=0;j<n;j++){ int i=order[j]; while (pos<n&&s[idx[pos]]+d[idx[pos]]>s[i]-d[i]+mid) pos++; if (!pos) continue; T t=get(root[pos-1],0,n-1,i+1,n-1); mnx=max(mnx,s[i]+d[i]+c-mid+t.first); mxx=min(mxx,s[i]-d[i]-c+mid+t.second); mny=max(mny,s[i]+d[i]+c-mid-t.second); mxy=min(mxy,s[i]-d[i]-c+mid-t.first); } for (int i=0;i<n;i++){ long long l=max(mnx-s[i],s[i]-mxy),r=min(mxx-s[i],s[i]-mny); int x=lower_bound(v.begin(),v.end(),l)-v.begin(),y=upper_bound(v.begin(),v.end(),r)-v.begin()-1; if (x<=y) ch=1; } if (ch){ kq=mid; hi=mid-1; } else lo=mid+1; } return kq; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...