#include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template struct LazySegmentTree{ using T = typename M::T; using L = typename M::L; int sz, height{}; vector seg; vector lazy; explicit LazySegmentTree(int n) { sz = 1; while(sz < n) sz <<= 1, height++; seg.assign(2*sz, M::e()); lazy.assign(2*sz, M::l()); } void set(int k, const T &x){ seg[k + sz] = x; } void build(){ for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[i<<1], seg[(i<<1)|1]); } T reflect(int k){ return lazy[k] == M::l() ? seg[k] : M::g(seg[k], lazy[k]); } void eval(int k){ if(lazy[k] == M::l()) return; lazy[(k<<1)|0] = M::h(lazy[(k<<1)|0], lazy[k]); lazy[(k<<1)|1] = M::h(lazy[(k<<1)|1], lazy[k]); seg[k] = reflect(k); lazy[k] = M::l(); } void thrust(int k){ for (int i = height; i; --i) eval(k>>i); } void recalc(int k) { while(k >>= 1) seg[k] = M::f(reflect((k<<1)|0), reflect((k<<1)|1));} void update(int a, int b, const L &x){ thrust(a += sz); thrust(b += sz-1); for (int l = a, r = b+1;l < r; l >>=1, r >>= 1) { if(l&1) lazy[l] = M::h(lazy[l], x), l++; if(r&1) --r, lazy[r] = M::h(lazy[r], x); } recalc(a); recalc(b); } T query(int a, int b){ // [l, r) thrust(a += sz); thrust(b += sz-1); T ll = M::e(), rr = M::e(); for(int l = a, r = b+1; l < r; l >>=1, r>>=1) { if (l & 1) ll = M::f(ll, reflect(l++)); if (r & 1) rr = M::f(reflect(--r), rr); } return M::f(ll, rr); } }; struct Monoid{ using T = int; using L = int; static T f(T a, T b) { return max(a, b); } static T g(T a, L b) { return max(a, b); } static L h(L a, L b) { return max(a, b); } static T e() { return -INF; } static L l() { return -INF; } }; int main() { int n; cin >> n; vector v(n); for (auto &&i : v) scanf("%d", &i); auto z = v; sort(z.begin(), z.end()); z.erase(unique(z.begin(), z.end()), z.end()); auto f = [&z](int x){return lower_bound(z.begin(),z.end(), x) - z.begin(); }; int m = z.size(); vector l(m, INF), r(m, -INF); for (int i = 0; i < n; ++i) { int x = f(v[i]); l[x] = min(l[x], i); r[x] = max(r[x], i); } LazySegmentTree seg(n); for (int i = 0; i < m; ++i) { seg.update(l[i], r[i]+1, z[i]); } for (int i = 0; i < n; ++i) { if(i) printf(" "); printf("%d", seg.query(i, i+1)); } puts(""); return 0; }