結果
問題 | No.649 ここでちょっとQK! |
ユーザー | るさ |
提出日時 | 2020-12-22 15:05:28 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,100 bytes |
コンパイル時間 | 342 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 79,672 KB |
最終ジャッジ日時 | 2024-09-21 14:11:37 |
合計ジャッジ時間 | 4,170 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,376 KB |
testcase_01 | AC | 42 ms
53,504 KB |
testcase_02 | AC | 41 ms
53,888 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | AC | 39 ms
53,248 KB |
testcase_08 | AC | 39 ms
53,376 KB |
testcase_09 | AC | 40 ms
53,352 KB |
testcase_10 | AC | 40 ms
53,572 KB |
testcase_11 | AC | 40 ms
53,504 KB |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 160 ms
77,644 KB |
testcase_28 | AC | 207 ms
78,292 KB |
testcase_29 | AC | 292 ms
79,672 KB |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 39 ms
53,376 KB |
testcase_33 | AC | 39 ms
53,492 KB |
testcase_34 | AC | 39 ms
53,120 KB |
testcase_35 | AC | 40 ms
53,376 KB |
ソースコード
class Order_Set: def __init__(self, deep:int): self.deep = deep self.length = 2 ** (deep+1) -1 self.value = [0] * self.length self.used = [False] * self.length self.free = [0] * self.length self.capacity = [0] * self.length for i in range(2 ** deep -1, self.length): self.free[i] = 1 self.capacity[i] = 1 for i in range(2 ** deep -2, -1, -1): self.free[i] = self.free[2*i+1] + self.free[2*i+2] + 1 self.capacity[i] = self.free[i] def insert(self, value:int, x=0, min_over=True): f = (False,) if self.free[x] == 0: if min_over: m = self.min_pop(x) f = (True, min(value, m)) value = max(value, m) else: m = self.max_pop(x) f = (True, max(value, m)) value = min(value, m) if not self.used[x]: self.used[x] = True self.value[x] = value t = x*2+1 while t != 0: t = (t-1) // 2 self.free[t] -= 1 return f if value == self.value[x]: return f elif value > self.value[x]: r = self.insert(value, x*2+2, True) if r[0]: t = self.value[x] self.value[x] = r[1] self.insert(t, x*2+1) return f else: r = self.insert(value, x*2+1, False) if r[0]: t = self.value[x] self.value[x] = r[1] self.insert(t, x*2+2) return f def min_pop(self, x:int): if x*2+1 >= self.length: r = self.value[x] self.used[x] = False x = x*2+1 while x != 0: x = (x-1) // 2 self.free[x] += 1 return r if self.used[x*2+1]: return self.min_pop(x*2+1) r = self.value[x] if self.used[x*2+2]: self.value[x] = self.min_pop(x*2+2) else: self.used[x] = False x = x*2+1 while x != 0: x = (x-1) // 2 self.free[x] += 1 return r def max_pop(self, x:int): if x*2+1 >= self.length: r = self.value[x] self.used[x] = False x = x*2+1 while x != 0: x = (x-1) // 2 self.free[x] += 1 return r if self.used[x*2+2]: return self.max_pop(x*2+2) r = self.value[x] if self.used[x*2+1]: self.value[x] = self.max_pop(x*2+1) else: self.used[x] = False x = x*2+1 while x != 0: x = (x-1) // 2 self.free[x] += 1 return r def erase(self, value:int): x = 0 while True: if x >= self.length or not self.used[x]: return if self.value[x] > value: x = x*2+1 elif self.value[x] < value: x = x*2+2 if self.value[x] == value: if x*2+1 < self.length: le = not self.used[x*2+1] re = not self.used[x*2+2] else: le = True re = True if le and re: self.used[x] = False x = x*2+1 while x != 0: x = (x-1) // 2 self.free[x] += 1 elif le: self.value[x] = self.min_pop(x*2+2) else: self.value[x] = self.max_pop(x*2+1) return def lower_bound(self, v:int, x=0): if x >= self.length or not self.used[x]: return None s = set([self.value[x]]) ll = self.lower_bound(v, x*2+1) rl = self.lower_bound(v, x*2+1) if not ll is None: s.add(ll) if not rl is None: s.add(rl) return min(s) def isin(self, v:int): return lower_bound(v) == v def index(self, id:int, x=0): if x*2+1 >= self.length: if id == 0: return self.value[x] else: raise IndexError("set index out of range") if not self.used[x]: raise IndexError("set index out of range") lp = self.capacity[x*2+1] - self.free[x*2+1] if id == lp: return self.value[x] elif id < lp: return self.index(id, x*2+1) else: return self.index(id-lp-1, x*2+2) q,k = map(int, input().split()) if q >= 1001: 1/0 os = Order_Set(10) for qi in range(q): query = list(map(int, input().split())) if query[0] == 1: os.insert((query[1], qi)) else: if os.capacity[0] - os.free[0] >= k: r = os.index(k-1) print(r[0]) os.erase(r) else: print(-1)