class Binary_Trie_Vertex: def __init__(self): self.left = None self.right = None self.parent = None self.size = 0 class Binary_Trie: def __init__(self, logn, ismulti = False): self.logn = logn self.root = Binary_Trie_Vertex() self.bi = [1 << i for i in range(logn)] self.multi = ismulti def add(self, x): V = self.root plus = False for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is None: V.right = Binary_Trie_Vertex() V.right.parent = V plus = True V = V.right else: if V.left is None: V.left = Binary_Trie_Vertex() V.left.parent = V plus = True V = V.left if plus or self.multi: while V.parent is not None: V.size += 1 V = V.parent V.size += 1 def remove(self, x): V = self.root for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is None: return False V = V.right else: if V.left is None: return False V = V.left V2 = V while V2.parent is not None: V2.size -= 1 V2 = V2.parent V2.size -= 1 while V.size == 0 and V != self.root: P = V.parent if P.right == V: P.right = None else: P.left = None if P.right is None and P.left is None: pass else: return True V = P return True def search(self, x): V = self.root for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is None: return False V = V.right else: if V.left is None: return False V = V.left return True def xor_min(self, x): xor = 0 V = self.root for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is not None: V = V.right else: xor += self.bi[i] V = V.left else: if V.left is not None: V = V.left else: xor += self.bi[i] V = V.right return xor def __getitem__(self, k): return self.Kth_element(k) def Kth_element(self, k): if k < 0: k = self.root.size + k k += 1 if k > self.root.size or k <= 0: return None ret = 0 V = self.root for i in range(self.logn - 1, -1, -1): if V.left is None: ret += self.bi[i] V = V.right elif V.right is None: V = V.left elif V.left.size >= k: V = V.left else: ret += self.bi[i] k -= V.left.size V = V.right return ret Q, k = map(int, input().split()) query = [list(map(int, input().split())) for _ in range(Q)] se = set() for tmp in query: if tmp[0] == 1: se.add(tmp[1]) lst = sorted(se) dic = {l:i for i, l in enumerate(lst)} le = len(lst) bt = Binary_Trie(le.bit_length(), True) for tmp in query: if tmp[0] == 1: bt.add(dic[tmp[1]]) else: ans = bt[k - 1] if ans is None: print(-1) else: print(lst[ans]) bt.remove(ans)