#include #include #include #include using namespace std; #define REP(i,s,e) for (i = s; i <= e; i++) #define rep(i,n) REP (i,0,(int)(n)-1) #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP (i,(int)(n)-1,0) #define INF (int)1e8 #define MOD (int)(1e9+7) typedef long long ll; int a[100100], nxt[100100], prv[100100]; int main(void) { int i, n; map> mp; scanf("%d",&n); REP (i,1,n) { scanf("%d",a+i); if (!mp.count(a[i])) mp[a[i]].first = i; else mp[a[i]].second = i; nxt[i] = i+1; prv[i] = i-1; } nxt[0] = 1; for (auto it = mp.rbegin(); it != mp.rend(); it++) { int left, right, p; left = it->second.first; right = it->second.second == 0 ? it->second.first : it->second.second; p = left; while ((p = nxt[p]) < right) a[p] = it->first; p = left; while ((p = nxt[p]) <= right) { nxt[prv[p]] = nxt[right]; prv[p] = prv[left]; } } REP (i,1,n) printf("%d%c",a[i],i < n ? ' ' : '\n'); return 0; }