#include // clang-format off #include using namespace std; using namespace atcoder; #define rep(i,n) for(int i=0;i<(n);i++) templateinline bool chmax(T &a,const S &b) {return (ainline bool chmin(T &a,const S &b) {return (a>b? a=b,1:0);} templateinline T floor(T a,S b) {if(b<0)a=-a,b=-b;return a>=0?a/b:(a+1)/b-1;} templateinline T ceil(T a,S b) {if(b<0)a=-a,b=-b;return a>0?(a-1)/b+1:a/b;} constexpr int dx[8]={1,0,-1,0,1,-1,1,-1},dy[8]={0,1,0,-1,1,-1,-1,1}; using ll = long long; // clang-format on #ifdef LOCAL #include #else #define debug(...) static_cast(0) #endif // 0始まりの座標へと圧縮する template struct CC { bool initialized; vector xs; CC() : initialized(false) {} void add(T x) { xs.push_back(x); } void init() { sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); initialized = true; } int operator()(T x) { if (!initialized) init(); return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1; } T decode(int i) { if (!initialized) init(); return xs[i]; } int size() { if (!initialized) init(); return xs.size(); } }; // // 区間更新 & 区間最大値取得 // using S = ll; using F = ll; const S INF = 8e18; const F ID = 8e18; S op(S a, S b) { return max(a, b); } S e() { return -INF; } S mapping(F f, S x) { return (f == ID ? x : f); } F composition(F f, F g) { return (f == ID ? g : f); } F id() { return ID; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector A(n); CC cc; rep(i, n) cin >> A[i], cc.add(A[i]); vector C(n); rep(i, n) C[i] = cc(A[i]); map> mp; rep(i, n) mp[C[i]].insert(i); debug(mp); lazy_segtree seg(C); rep(x, cc.size()) { if (mp.count(x) == 0) continue; int l = 1001001001; int r = -1; for (auto i : mp[x]) { // if (seg.get(i) != x) continue; chmin(l, i), chmax(r, i); } if (r == -1) continue; seg.apply(l, r + 1, x); } rep(i, C.size()) cout << cc.decode(seg.get(i)) << ' '; cout << endl; return 0; }