## https://yukicoder.me/problems/no/2809 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, Q = map(int, input().split()) A = list(map(int ,input().split())) queries = [] for _ in range(Q): values = tuple(map(int, input().split())) queries.append(values) # A, xの座標圧縮 a_set = set(A) for values in queries: if values[0] == 1: _, _, x = values a_set.add(x) a_list = list(a_set) a_list.sort() a_map = {} for i, a in enumerate(a_list): a_map[a] = i + 1 a_max = len(a_list) # ソート済みのでーたかんりようとしてBinaryIndexTreeを利用 bit = BinaryIndexTree(a_max) non_sort_a_map = {} for a in A: bit.add(a_map[a], 1) for i in range(N): non_sort_a_map[i] = a_map[A[i]] # クエリを処理していく for values in queries: if values[0] == 1: _, k, x = values k -= 1 non_sort_a_map[k] = a_map[x] elif values[0] == 2: # ソートしていく remove_target_list = [] for k in non_sort_a_map.keys(): a_ = bit.least_upper_bound(k + 1) remove_target_list.append(a_) for a_ in remove_target_list: bit.add(a_, -1) for v in non_sort_a_map.values(): bit.add(v, 1) non_sort_a_map.clear() else: # 表示 _, k = values k -= 1 if k in non_sort_a_map: a_ = non_sort_a_map[k] print(a_list[a_ - 1]) else: a_ = bit.least_upper_bound(k + 1) print(a_list[a_ - 1]) if __name__ == "__main__": main()