#include #include #include #include #define llint long long #define inf 1e18 using namespace std; typedef pair P; struct LiChaoTree{ int size; vector

seg; vector x; LiChaoTree(){} LiChaoTree(int size){ this->size = size; seg.resize(1<<(size+1)); x.resize(1<= 1){ ret = min(ret, calc(seg[i], X)); i /= 2; } return ret; } void add(int k, int l, int r, P f) { int m = (l+r)/2; if(calc(f, x[m]) < calc(seg[k], x[m])) swap(seg[k], f); bool L = (calc(f, x[l]) < calc(seg[k], x[l])), R = (calc(f, x[r]) < calc(seg[k], x[r])); if(L == R) return; if(L) add(k*2, l, m, f); if(R) add(k*2+1, m+1, r, f); } void addSegment(int a, int b, int k, int l, int r, P f) { if(b < l || r < a) return; if(a <= l && r <= b){ add(k, l, r, f); return; } addSegment(a, b, k*2, l, (l+r)/2, f); addSegment(a, b, k*2+1, (l+r)/2+1, r, f); } void addSegment(int a, int b, llint p, llint q) //区間[x[a], x[b]]に線分px+qを追加 { addSegment(a, b, 1, 0, (1< r) return; if(l == r){ ans[l] = min(ans[l], s[r]-s[l-1] + 1); return; } llint m = (l+r)/2; llint size = 0; for(int len = r-l+2; len; len/=2) size++; lct = LiChaoTree(size); lct.init(); for(int i = 0; i < (1<= m+1; i--){ mn = min(mn, lct.query(i-(l-1)) + i*i + s[i]); ans[i] = min(ans[i], mn); } lct.init(); for(int i = 0; i < (1<> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i]; for(int i = 1; i <= n; i++) ans[i] = inf; calc(1, n); for(int i = 1; i <= n; i++) cout << ans[i] << "\n"; flush(cout); return 0; }