#include using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for(int i=0; ibool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b class LazySegmentTree{ ll n; vector node; vector lazy; vector lazyFlag; public: LazySegmentTree(vector v){ int size = v.size(); n = 1; while(n < size) n *= 2; node.resize(2*n-1, init()); lazy.resize(2*n-1, id()); lazyFlag.resize(2*n-1, false); for(int i = 0; i < size; i++){ node[n-1+i] = v[i]; } for(int i = n-2; i >= 0; i--){ node[i] = op(node[2*i+1], node[2*i+2]); } } // k番目のノードについて遅延評価 void eval(int k, int l, int r){ if(lazyFlag[k]){ if(r - l > 1){ lazy[2*k+1] = composition(lazy[2*k+1], lazy[k]); lazy[2*k+2] = composition(lazy[2*k+2], lazy[k]); lazyFlag[2*k+1] = lazyFlag[2*k+2] = true; } node[k] = mapping(lazy[k], node[k]); lazy[k] = id(); lazyFlag[k] = false; } } // 区間更新 // update val in [a, b] --> update(a, b+1) void update(int a, int b, F x, int k=0, int l=0, int r=-1){ if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b){ lazy[k] = composition(lazy[k], x); lazyFlag[k] = true; eval(k, l, r); } else{ update(a, b, x, 2*k+1, l, (l+r)/2); update(a, b, x, 2*k+2, (l+r)/2, r); node[k] = op(node[2*k+1], node[2*k+2]); } } void abs_update(int idx, S val){ idx += n-1; node[idx] = val; while(idx > 0){ idx = (idx-1)/2; node[idx] = op(node[2*idx+1], node[2*idx+2]); } } // get val in [a, b] --> get_val(a, b+1) S get_val(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = n; if(b <= l || r <= a) return init(); eval(k, l, r); if(a <= l && r <= b) return node[k]; S vl = get_val(a, b, 2*k+1, l, (l+r)/2); S vr = get_val(a, b, 2*k+2, (l+r)/2, r); return op(vl, vr); } }; struct S { ll x; int len; }; /// 例 S op(S lhs, S rhs){ return S{lhs.x + rhs.x, lhs.len + rhs.len}; } S init(){ return S{0, 0}; } using F = long long; S mapping(F x, S s){ return S{x * s.len, s.len}; } F composition(F lhs, F rhs){ return rhs; } F id(){ return 0; } int main(){ int N; cin >> N; vector A(N); for(auto& a : A) cin >> a; map left, right; auto update_left = [&](ll key, int val){ if(left.count(key) == 0) left[key] = val; else chmin(left[key], val); }; REP(i,N){ update_left(A[i], i); right[A[i]] = i; } vector vec(N, S{0, 1}); LazySegmentTree stree(vec); for(auto& [a, L] : left){ auto R = right[a]; stree.update(L, R+1, a); } REP(i,N){ auto [b, _] = stree.get_val(i, i+1); cout << b << " "; } cout << "\n"; return 0; }