import std; const segSize = 1 << 20; int[segSize * 2] seg; int[segSize * 2] segTime; // 更新された時刻 void update(int l, int r, int v, int time) { l += segSize; r += segSize; while (l < r) { if (l % 2 == 1) { seg[l] = v; segTime[l] = time; l++; } l /= 2; if (r % 2 == 1) { seg[r - 1] = v; segTime[r - 1] = time; r--; } r /= 2; } } int get(int ind) { ind += segSize; int v = seg[ind]; int time = segTime[ind]; while (true) { ind /= 2; // 上にのぼる if (ind == 0) break; if (time < segTime[ind]) { // 更新が新しい v = seg[ind]; time = segTime[ind]; } } return v; } // 親の更新を子に伝搬する(親は更新されない) void propagate() { void rec(int ind) { if (ind * 2 >= seg.length) return; int lt = ind * 2; int rt = ind * 2 + 1; if (segTime[ind] > segTime[lt]) { // 左の子: 親の方が新しいなら子に伝搬 seg[lt] = seg[ind]; segTime[lt] = segTime[ind]; } if (segTime[ind] > segTime[rt]) { // 右の子: 親の方が新しいなら子に伝搬 seg[rt] = seg[ind]; segTime[rt] = segTime[ind]; } rec(lt); rec(rt); } rec(1); } void calc(int[] a) { int n = cast(int)a.length; int[int] first, last; foreach_reverse(i; 0..n) first[a[i]] = i; foreach (i; 0..n) last[a[i]] = i; int time = 1; foreach (k; first.keys.sort) { int l = first[k]; int r = last[k]; update(l, r + 1, k, time++); } propagate(); auto ans = seg[segSize..$].take(n).map!text.join(' '); writeln(ans); } void main() { read; auto a = readints; calc(a); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T=string)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readints = reads!int;