#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using namespace std; template ostream& operator<<(ostream& o,const pair &p){ return o<<"("< ostream& operator<<(ostream& o,const vector &vc){ o<<"{"; for(const T& v:vc) o< using V = vector; template using VV = vector>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #ifdef LOCAL #define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl #else #define show(x) true #endif struct CHT{ using D = ll; typedef pair P; vector

deq; int s,sd,t; CHT():s(0),sd(0),t(0){} void add(D a,D b){ //add ax+b a:(広義)単調減少!!! P p(a,b); while(s+1=f(deq[s+1],x)) s++; return f(deq[s],x); } D decr_query(D x){ //x:単調減少の時,これを繰り返し呼ぶ(間にaddが挟まるのはOK) if(sd>=t) sd=t-1; while(sd+1=f(deq[sd+1],x)) sd++; while(sd>0&&f(deq[sd],x)1){ int m=(lb+ub)/2; if(isright(deq[m],deq[m+1],x)) lb=m; else ub=m; } return f(deq[ub],x); } bool isright(P& a,P& b,D x){ return f(a,x)>=f(b,x); } bool check(P& a,P& b,P& c){ return (b.fs-a.fs)*(c.sc-b.sc)>=(b.sc-a.sc)*(c.fs-b.fs); } D f(P &p,int x){ return p.fs*x+p.sc; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !! cout << fixed << setprecision(20); int N; cin >> N; V A(N); rep(i,N) cin >> A[i]; V S(N+1); rep(i,N) S[i+1] = S[i] + A[i]; const ll inf = 1e18; V ans(N,inf); function f = [&](int L,int R){ if(L == R) return; int m = (L+R)/2; //L<=j<=m<=p=m+1;i--){ ll val=cht.query(i) + i*i + S[i]; chmin(mn,val); chmin(ans[i-1],mn); } } //L<=j<=p