結果
問題 | No.649 ここでちょっとQK! |
ユーザー | 👑 rin204 |
提出日時 | 2022-07-04 14:21:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 794 ms / 3,000 ms |
コード長 | 3,882 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 81,784 KB |
実行使用メモリ | 167,840 KB |
最終ジャッジ日時 | 2024-12-14 03:43:47 |
合計ジャッジ時間 | 13,818 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,788 KB |
testcase_01 | AC | 41 ms
53,920 KB |
testcase_02 | AC | 40 ms
53,524 KB |
testcase_03 | AC | 235 ms
97,132 KB |
testcase_04 | AC | 460 ms
167,684 KB |
testcase_05 | AC | 475 ms
167,840 KB |
testcase_06 | AC | 310 ms
97,068 KB |
testcase_07 | AC | 40 ms
53,108 KB |
testcase_08 | AC | 40 ms
54,724 KB |
testcase_09 | AC | 40 ms
53,212 KB |
testcase_10 | AC | 41 ms
53,560 KB |
testcase_11 | AC | 41 ms
53,280 KB |
testcase_12 | AC | 429 ms
116,700 KB |
testcase_13 | AC | 425 ms
116,468 KB |
testcase_14 | AC | 430 ms
116,796 KB |
testcase_15 | AC | 444 ms
117,004 KB |
testcase_16 | AC | 424 ms
117,664 KB |
testcase_17 | AC | 479 ms
112,744 KB |
testcase_18 | AC | 524 ms
126,312 KB |
testcase_19 | AC | 563 ms
133,568 KB |
testcase_20 | AC | 587 ms
132,212 KB |
testcase_21 | AC | 639 ms
140,624 KB |
testcase_22 | AC | 666 ms
139,708 KB |
testcase_23 | AC | 705 ms
136,464 KB |
testcase_24 | AC | 739 ms
134,172 KB |
testcase_25 | AC | 756 ms
156,016 KB |
testcase_26 | AC | 794 ms
142,284 KB |
testcase_27 | AC | 80 ms
73,440 KB |
testcase_28 | AC | 80 ms
71,756 KB |
testcase_29 | AC | 72 ms
69,364 KB |
testcase_30 | AC | 388 ms
108,800 KB |
testcase_31 | AC | 372 ms
109,556 KB |
testcase_32 | AC | 41 ms
53,360 KB |
testcase_33 | AC | 41 ms
52,596 KB |
testcase_34 | AC | 40 ms
53,736 KB |
testcase_35 | AC | 41 ms
53,552 KB |
ソースコード
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)