## https://yukicoder.me/problems/no/318 class BinaryIndexTree: """ フェニック木(BinaryIndexTree)の基本的な機能を実装したクラス """ def __init__(self, size): self.size = size self.array = [0] * (size + 1) def add(self, x, a): index = x while index <= self.size: self.array[index] += a index += index & (-index) def sum(self, x): index = x ans = 0 while index > 0: ans += self.array[index] index -= index & (-index) return ans def least_upper_bound(self, value): if self.sum(self.size) < value: return -1 elif value <= 0: return 0 m = 1 while m < self.size: m *= 2 k = 0 k_sum = 0 while m > 0: k0 = k + m if k0 < self.size: if k_sum + self.array[k0] < value: k_sum += self.array[k0] k += m m //= 2 if k < self.size: return k + 1 else: return -1 def main(): N = int(input()) A = list(map(int, input().split())) # 座標圧縮 a_set = set(A) a_list = list(a_set) a_list.sort() a_map = {} for i, a in enumerate(a_list): a_map[a] = i + 1 a_interval_map = {} for i in range(N): a = A[i] if a not in a_interval_map: a_interval_map[a] = [i, i] else: a_interval_map[a][1] = i event_map = {} for a, (s, g) in a_interval_map.items(): if s not in event_map: event_map[s] = [] event_map[s].append((a, g)) answer = [0] * N event_map2 = {} bit = BinaryIndexTree(len(a_list)) for t in range(N): if t in event_map: for a, g in event_map[t]: a_ = a_map[a] bit.add(a_, 1) if g not in event_map2: event_map2[g] = [] event_map2[g].append(a) x = bit.sum(bit.size) a_ = bit.least_upper_bound(x) a = a_list[a_ - 1] answer[t] = a if t in event_map2: for a in event_map2[t]: a_ = a_map[a] bit.add(a_, -1) print(" ".join(map(str, answer))) if __name__ == '__main__': main()