#include #define rep(i,a,b) for(int i=a;i struct LazySegTree { // [L,R) #define def 0 #define ldef -1 V comp(V l, V r) { return l + r; } void setLazy(int i, V v) { lazy[i] = v; } void push(int k, int l, int r) { if (lazy[k] != ldef) { // modify------------------------------ V sm = lazy[k]; int kk = k; while (kk < NV) { kk *= 2; sm *= 2; } dat[k] = sm; // ------------------------------------ if (r - l > 1) { setLazy(k * 2 + 1, lazy[k]); setLazy(k * 2 + 2, lazy[k]); } setLazy(k, ldef); } } vector dat, lazy; LazySegTree() { dat.resize(NV * 2, def); lazy.resize(NV * 2, ldef); } void update(int a, int b, V v, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return; if (a <= l && r <= b) { setLazy(k, v); push(k, l, r); } else { update(a, b, v, k * 2 + 1, l, (l + r) / 2); update(a, b, v, k * 2 + 2, (l + r) / 2, r); dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]); } } V get(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return def; if (a <= l && r <= b) return dat[k]; auto x = get(a, b, k * 2 + 1, l, (l + r) / 2); auto y = get(a, b, k * 2 + 2, (l + r) / 2, r); return comp(x, y); } void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); } V get(int a, int b) { return get(a, b, 0, 0, NV); } }; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N; int A[101010]; //--------------------------------------------------------------------------------------------------- LazySegTree st; void _main() { cin >> N; rep(i, 0, N) scanf("%d", &A[i]); rep(i, 0, N) st.update(i, i + 1, A[i]); map> m; rep(i, 0, N) m[A[i]].push_back(i); for (auto p : m) { int i = p.first; auto v = p.second; int mi, ma; mi = ma = v[0]; for (int j : v) mi = min(mi, j), ma = max(ma, j); //printf("[%d %d]\n", mi, ma); st.update(mi, ma + 1, i); } printf("%lld", st.get(0, 0 + 1) / 2); rep(i, 1, N) printf(" %lld", st.get(i, i + 1)); printf("\n"); }