#include #include #include using namespace std; template class LazySegTree{ private: int n; vector arr, lazy; const T INF = 0; public: LazySegTree(int _n){ n = 1; while(n < _n) n <<= 1; arr = vector(n*2, INF); lazy = vector(n*2, INF); } void eval(int k){ if(lazy[k] == INF) return; if(k < n-1){ lazy[k*2+1] = lazy[k]; lazy[k*2+2] = lazy[k]; } arr[k] = lazy[k]; lazy[k] = INF; } void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){ if(r == -1) r = n; eval(k); if(a <= l && r <= b){ lazy[k] = x; eval(k); }else if(a < r && l < b){ update(a, b, x, k*2+1, l, (l+r)/2); update(a, b, x, k*2+2, (l+r)/2, r); } } T query(int a, int b, int k = 0, int l = 0, int r = -1){ if(r == -1) r = n; eval(k); if(r <= a || b <= l) return INF; else if(a <= l && r <= b) return arr[k]; else{ return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r); } } }; int main(){ int n; cin >> n; vector a(n); for(auto &p: a) cin >> p; map> a2; for(int i = 0; i < n; i++){ if(a2.count(a[i]) == 0){ a2[a[i]] = make_pair(i, i); }else{ a2[a[i]].second = i; } } LazySegTree d(n); for(auto &p: a2){ d.update(p.second.first, p.second.second+1, p.first); } for(int i = 0; i < n; i++){ if(i != 0) cout << " "; cout << d.query(i, i+1); } cout << endl; return 0; }