#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i) #define REP(i,n) FOR(i,0,n) #define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define SZ(i) ((int)i.size()) #define GI(i) (scanf("%d",&i)) #define GLL(i) (scanf("%lld",&i)) #define GD(i) (scanf("%lf",&i)) #define PB push_back #define MP make_pair #define MT make_tuple #define GET0(x) (get<0>(x)) #define GET1(x) (get<1>(x)) #define GET2(x) (get<2>(x)) #define ALL(X) (X).begin(),(X).end() #define LLMAX (1LL<<60) #define LLMIN -(1LL<<60) #define IMAX (1<<30) #define IMIN -(1<<30) typedef long long LL; using namespace std; const int MAX_N = 1 << 18; class RangeUpdateRangeSum{ public: int sz; LL node[MAX_N], lazy[MAX_N]; RangeUpdateRangeSum(int n) { sz = 1; while (n > sz )sz *= 2; for (int i = 0; i < 2 * sz - 1; i++)lazy[i] = -1; } void lazy_evaluate_node(int k, int l, int r) { if (lazy[k] != -1) { node[k] = lazy[k] * (r - l); if (r - l > 1) { lazy[k * 2 + 1] = lazy[k]; lazy[k * 2 + 2] = lazy[k]; } lazy[k] = -1; } } void update(int a, int b, LL v){ update(a,b,v,0,0,sz); } void update(int a, int b, LL v, int k, int l, int r) { lazy_evaluate_node(k, l, r); if (r <= a || b <= l)return; if (a <= l && r <= b) { lazy[k] = v; lazy_evaluate_node(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); node[k] = node[k * 2 + 1] + node[k * 2 + 2]; } } LL sum(int a, int b){ return sum(a,b,0,0,sz); } LL sum(int a, int b, int k, int l, int r) { lazy_evaluate_node(k, l, r); if (r <= a || b <= l)return 0; if (a <= l && r <= b)return node[k]; LL x = sum(a, b, k * 2 + 1, l, (l + r) / 2); LL y = sum(a, b, k * 2 + 2, (l + r) / 2, r); return x + y; } }; int main() { int n; cin >> n; vector a(n); REP(i, n)cin >> a[i]; mapleft, right; REP(i, n) { if (left.count(a[i]) == 0) left[a[i]] = i; } for (int i = n - 1; i >= 0; i--) { if (right.count(a[i]) == 0) { right[a[i]] = i; } } RangeUpdateRangeSum seg(n); REP(i, n)seg.update(i,i+1,a[i]); for (auto v : left) { if (right.count(v.first)) { seg.update(v.second, right[v.first] + 1, v.first); } } REP(i, n)printf("%d ",(int)seg.sum(i,i+1)); printf("\n"); return 0; }