#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second using ll=long long;using pii=pair;using vb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; template struct SegTreeLazy { static const V zero = 0; static const V def = 0; struct Node { V dat; V lazy; bool flag; Node() : dat(def), lazy(zero), flag(false) {} }; static V merge(const V &l, const V &r) { return l + r; } static V mul(const V &v, const int a) { return v * a; } const int N; vector seg; SegTreeLazy(int size) : N(p2(size)), seg(N * 2) {}; void update(int a, int b, V v) { update(a, b, v, 0, 0, N); } void push(int k, int l, int r) { if (seg[k].flag) { seg[k].dat = seg[k].lazy; if (r - l > 1) { seg[k * 2 + 1].lazy = seg[k].lazy; seg[k * 2 + 2].lazy = seg[k].lazy; seg[k * 2 + 1].flag = true; seg[k * 2 + 2].flag = true; } seg[k].lazy = zero; seg[k].flag = false; } } V query(int a, int b) { return query(a, b, 0, 0, N); } private: 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) { seg[k].lazy = v; seg[k].flag = true; 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); seg[k].dat = merge(seg[k * 2 + 1].dat, seg[k * 2 + 2].dat); } } V query(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return 0; if (a <= l && r <= b) return seg[k].dat; V x = query(a, b, k * 2 + 1, l, (l + r) / 2); V y = query(a, b, k * 2 + 2, (l + r) / 2, r); return merge(x, y); } static int p2(int n, int m=1) { return m >= n ? m : p2(n, m * 2); } }; void Main() { int N; scanf("%d", &N); map pos; rep(i, N) { int a; scanf("%d", &a); if (pos.count(a)==0) pos[a].fst = pos[a].snd = i; else pos[a].snd = i; } SegTreeLazy seg(N); forr(nfl, pos) { int f, l; tie(f, l) = nfl.snd; seg.update(f, l+1, nfl.fst); //cout << "seg.seg:"; rep(ii,SZ(seg.seg)) cout << ' ' << seg.seg[ii].lazy; cout << endl; } rep(i, N) { _p("%d ", seg.query(i, i+1)); } _p("\n"); } int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }