## https://yukicoder.me/problems/no/649 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(): Q, K = map(int, input().split()) queries = [] for _ in range(Q): values = tuple(map(int, input().split())) queries.append(values) # 座標圧縮 v_set = set() for values in queries: if values[0] == 1: v_set.add(values[1]) v_list = list(v_set) v_list.sort() v_map = {} for i, v in enumerate(v_list): v_map[v] = i + 1 v_max = len(v_list) bit = BinaryIndexTree(v_max) for values in queries: if values[0] == 1: _, v = values bit.add(v_map[v], 1) else: if bit.sum(bit.size) < K: print(-1) else: v = bit.least_upper_bound(K) print(v_list[v - 1]) bit.add(v, - 1) if __name__ == "__main__": main()