#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; typedef __int128_t lll; int n; ll a[200020]; ll s[200020]; ll ans[200020]; void solve(int l, int r){ if(l>r) return; if(l==r){ ans[l]=min(ans[l], 1+a[l]); return; } int m=(l+r)/2; deque cht; for(int i=m; i<=r; i++){ ll a0=-2*(i+1), b0=(ll)(i+1)*(i+1)+s[i+1]; while(cht.size()>1){ int i1=cht[cht.size()-1], i2=cht[cht.size()-2]; ll a1=-2*i1, b1=(ll)i1*i1+s[i1]; ll a2=-2*i2, b2=(ll)i2*i2+s[i2]; if((lll)(b1-b2)*(a1-a0)<(lll)(b0-b1)*(a2-a1)) break; cht.pop_back(); } cht.push_back(i+1); } vector vm1(m-l+1), vm2(r-m+1); for(int i=l; i<=m; i++){ while(cht.size()>1){ int i1=cht[0], i2=cht[1]; ll a1=-2*i1, b1=(ll)i1*i1+s[i1]; ll a2=-2*i2, b2=(ll)i2*i2+s[i2]; if(a1*(ll)i+b11){ int i1=cht[cht.size()-1], i2=cht[cht.size()-2]; ll a1=-2*i1, b1=(ll)i1*i1-s[i1]; ll a2=-2*i2, b2=(ll)i2*i2-s[i2]; if((lll)(b1-b2)*(a1-a0)<(lll)(b0-b1)*(a2-a1)) break; cht.pop_back(); } cht.push_back(i); } for(int i=m; i<=r; i++){ while(cht.size()>1){ int i1=cht[0], i2=cht[1]; ll a1=-2*i1, b1=(ll)i1*i1-s[i1]; ll a2=-2*i2, b2=(ll)i2*i2-s[i2]; if(a1*(ll)(i+1)+b1=m; i--){ mn=min(mn, vm2[i-m]); ans[i]=min(ans[i], mn); } solve(l, m-1); solve(m+1, r); } int main() { cin>>n; s[0]=0; for(int i=0; i>a[i]; s[i+1]=s[i]+a[i]; } const ll INF=1e18; fill(ans, ans+n, INF); solve(0, n-1); for(int i=0; i