#include using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) for (int i = (a) - 1; i >= 0; i--) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) template bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } typedef long long ll; const int inf = 1e9; struct RBST { struct node { int val, size; node *lch, *rch; int mx; int lazy; node(int val) : val(val), mx(val), size(1), lch(0), rch(0), lazy(-1) {} }; node *root; RBST(int n) { root = build(0, n); } node *build(int l, int r) { if (r - l == 1) return new node(0); return merge(build(l, (l + r) / 2), build((l + r) / 2, r)); } unsigned xor32() { static unsigned z = time(NULL); z ^= z << 13; z ^= z >> 17; z ^= z << 5; return z; } int size(node *x) { return x ? x->size : 0; } int mx(node *x) { return x ? x->mx : -inf; } node *push(node *x) { x->size = 1 + size(x->lch) + size(x->rch); if (x->lazy != -1) { x->val = x->lazy; if (x->lch) x->lch->lazy = x->lazy; if (x->rch) x->rch->lazy = x->lazy; x->lazy = -1; } x->mx = max({ x->val, mx(x->lch), mx(x->rch) }); return x; } node *merge(node *x, node *y) { if (!x) return y; if (!y) return x; if (xor32() % (size(x) + size(y)) < size(x)) { x = push(x); x->rch = merge(x->rch, y); return push(x); } else { y = push(y); y->lch = merge(x, y->lch); return push(y); } } pair split(node *x, int k) { if (!x) return{ 0, 0 }; x = push(x); if (size(x->lch) >= k) { auto p = split(x->lch, k); x->lch = p.second; return{ p.first, push(x) }; } else { auto p = split(x->rch, k - size(x->lch) - 1); x->rch = p.first; return{ push(x), p.second }; } } node *insert(node *x, int k, int v) { auto p = split(x, k); node *n = new node(v); return merge(p.first, merge(n, p.second)); } node *erase(node *x, int k) { auto p = split(x, k); return merge(p.first, split(p.second, 1).second); } void push_back(int v) { root = merge(root, new node(v)); } int lower_bound(node *x, int v) { if (!x) return 0; if (v < x->val) return lower_bound(x->lch, v); return lower_bound(x->rch, v) + size(x->lch) + 1; } node *at(node *x, int k) { if (size(x->lch) == k) return x; if (size(x->lch) > k) return at(x->lch, k); return at(x->rch, k - size(x->lch) - 1); } void update(int a, int b, int v) { auto x = split(root, b); auto y = split(x.first, a); y.second->lazy = v; root = merge(merge(y.first, y.second), x.second); } int query(int a, int b) { auto x = split(root, b); auto y = split(x.first, a); ll ret = mx(y.second); root = merge(merge(y.first, y.second), x.second); return ret; } }; int main() { int n; cin >> n; vector a(n); rep(i, n) scanf("%d", &a[i]); map first, last; repr(i, n) first[a[i]] = i; rep(i, n) last[a[i]] = i; RBST tr(n); rep(i, n) tr.update(i, i + 1, a[i]); for (auto kv : first) if (last.count(kv.first)) { tr.update(kv.second, last[kv.first] + 1, kv.first); } rep(i, n) printf("%d ", (int)tr.query(i, i + 1)); cout << endl; return 0; }