#ifdef t9unkubj #include"template.h" //#include"template_no_debug.h" #else #undef _GLIBCXX_DEBUG #pragma GCC optimize("O3") #define dbg(...) 199958 using namespace std; #include using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; using vi=vc; using vvi=vc; using vvvi=vc; using vl=vc; using vvl=vc; using vvvl=vc; templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define is insert #define bg begin() #define ed end() void scan(int&a) { cin >> a; } void scan(ll&a) { cin >> a; } void scan(string&a) { cin >> a; } void scan(char&a) { cin >> a; } void scan(uint&a) { cin >> a; } void scan(ull&a) { cin >> a; } void scan(bool&a) { cin >> a; } void scan(ld&a){ cin>> a;} template void scan(vector&a) { for(auto&x:a) scan(x); } void read() {} template void read(Head&head, Tail&... tail) { scan(head); read(tail...); } #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define CHR(...) char __VA_ARGS__; read(__VA_ARGS__); #define DBL(...) double __VA_ARGS__; read(__VA_ARGS__); #define LD(...) ld __VA_ARGS__; read(__VA_ARGS__); #define VC(type, name, ...) vector name(__VA_ARGS__); read(name); #define VVC(type, name, size, ...) vector> name(size, vector(__VA_ARGS__)); read(name); void print(int a) { cout << a; } void print(ll a) { cout << a; } void print(string a) { cout << a; } void print(char a) { cout << a; } void print(uint a) { cout << a; } void print(bool a) { cout << a; } void print(ull a) { cout << a; } void print(double a) { cout << a; } void print(ld a){ cout<< a; } template void print(vectora) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}cout< void PRT(T a) { print(a); cout < void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; } template bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template bool chmax(T &x, F y){ if(x int popcount(T n){ return __builtin_popcountll(n); } template T sum(vc&a){ return accumulate(all(a),T(0)); } template T max(vc&a){ return *max_element(all(a)); } template T min(vc&a){ return *min_element(all(a)); } template void unique(vc&a){ a.erase(unique(all(a)),a.end()); } vvi readgraph(int n,int m,int off = -1){ vvi g(n); rep(i, m){ int u,v; cin>>u>>v; u+=off,v+=off; g[u].push_back(v); g[v].push_back(u); } return g; } vvi readtree(int n,int off=-1){ return readgraph(n,n-1,off); } template vc presum(vc &a){ vc ret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc &operator+=(vc &a,F b){ for (auto&v:a)v += b; return a; } template vc &operator-=(vc&a,F b){ for (auto&v:a)v-=b; return a; } template vc &operator*=(vc&a,F b){ for (auto&v:a)v*=b; return a; } #endif double pass_time=0; template struct dual_seg{ int n; using F=function; F op; T id; vectorlazy; int log=0; dual_seg(int n_,F op,T id):n(n_),op(op),id(id){ while((1<(n*2,id); } void set(int i,T x){ assert(0<=i&&i=1;j--){ push(i>>j); } lazy[i]=x; } void apply(int l,int r,T x){ assert(0<=l&&l<=r&&r<=n); if(l==r)return; l+=n,r+=n; for(int i=log;i>=1;i--){ if(((l>>i)<>i); if(((r>>i)<>i); } while(l>=1,r>>=1; } } T get(int i){ assert(0<=i&&i=1;j--){ push(i>>j); } return lazy[i]; } void push(int k){ all_apply(k*2,lazy[k]),all_apply(k*2+1,lazy[k]); lazy[k]=id; } void all_apply(int k,T x){ lazy[k]=op(lazy[k],x); } }; /* 分割統治をする ある左端を含む区間について左側の区間に対しての最小値が求まれば良い よく考えるとこれは最高時の係数が等しい二次関数なので 高々一つしか交わらない曲線群! よってchtにのる 区間にたいして準線型でできるので全体でlog2個 */ struct lichao_tree{ int n; vector>node; vectorxs; const long long inf=2e18; lichao_tree(vector&x):xs(x){ n=1; while(n{0,inf,-1}); } long long get_val(arraya,long long x){ return (a[0]+x)*(a[0]+x)+a[1]; } void apply(int l,int r,array p,int idx){//[l,r]にpを追加する long long mid=(l+r)>>1; int lb=get_val(node[idx],xs[l])>get_val(p,xs[l]); int mb=get_val(node[idx],xs[mid])>get_val(p,xs[mid]); if(mb)swap(node[idx],p); if(l+1>=r)return; else if(lb!=mb)apply(l,mid,p,idx*2); else apply(mid,r,p,idx*2+1); } void apply(long long a,long long b,ll i){ apply(0,n,array{a,b,i},1); } array get(int i){ long long x=xs[i]; long long ret=get_val(node[i+=n],x); ll idx=node[i][2]; while(i){ if(chmin(ret,get_val(node[i],x)))idx=node[i][2]; i>>=1; } return {ret,idx}; } }; void solve(){ INT(n); VC(int,a,n); dual_seg seg(n,[](ll a,ll b){return min(a,b);},1e18); auto sol=[&](auto&sol,int l,int r)->array{ if(l+1==r){ seg.apply(l,l+1,a[l]+1); return {vl{a[l]},vl{a[l]}}; } if(l>r)return {vl{},vl{}}; int mid=l+r>>1; auto r1=sol(sol,l,mid); auto r2=sol(sol,mid,r); dbg(r1[0],r1[1],r2[0],r2[1],l,r,mid); //r2を載せる { vl idx(r2[0].size()+2); iota(all(idx),1); lichao_tree g(idx); rep(i,r2[0].size()){ g.apply(i+1,r2[0][i],i); } drep(i,r1[1].size()){ int k=r1[1].size()-i-1; auto res=g.get(k); seg.apply(mid-k-1,res[1]+mid+1,res[0]+r1[1][k]); } } //r1をのせる  { vl idx(r1[1].size()+2); iota(all(idx),1); lichao_tree g(idx); rep(i,r1[1].size()){ g.apply(i+1,r1[1][i],i); } rep(i,r2[1].size()){ int k=i; auto res=g.get(k); seg.apply(mid-res[1]-1,mid+k+1,res[0]+r2[0][k]); } } arrayres{}; rep(i,2)res[i].resize(r-l); rep(i,r1[0].size()){ res[0][i]=r1[0][i]; } rep(i,r2[0].size()){ res[0][i+r1[0].size()]=r2[0][i]+r1[0].back(); } rep(i,r2[0].size()){ res[1][i]=r2[1][i]; } rep(i,r1[0].size()){ res[1][i+r2[0].size()]=r1[1][i]+r2[1].back(); } return res; }; sol(sol,0,n); rep(i,n)PRT(seg.get(i)); } signed main(){ #ifdef t9unkubj freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin.tie(0)->sync_with_stdio(0); pass_time=clock(); int t=1; //cin>>t; while(t--)solve(); pass_time=clock()-pass_time; dbg(pass_time/CLOCKS_PER_SEC); }