結果
問題 | No.2804 Fixer And Ratism |
ユーザー | 👑 rin204 |
提出日時 | 2024-07-12 21:14:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,399 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 76,860 KB |
最終ジャッジ日時 | 2024-07-12 21:14:23 |
合計ジャッジ時間 | 5,823 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,920 KB |
testcase_01 | AC | 38 ms
54,736 KB |
testcase_02 | AC | 37 ms
53,324 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 71 ms
73,632 KB |
testcase_10 | WA | - |
testcase_11 | AC | 121 ms
76,412 KB |
testcase_12 | WA | - |
testcase_13 | AC | 79 ms
76,376 KB |
testcase_14 | AC | 105 ms
76,436 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 86 ms
76,696 KB |
testcase_18 | WA | - |
testcase_19 | AC | 71 ms
71,340 KB |
testcase_20 | WA | - |
testcase_21 | AC | 125 ms
76,468 KB |
testcase_22 | WA | - |
testcase_23 | AC | 144 ms
76,252 KB |
testcase_24 | WA | - |
testcase_25 | AC | 145 ms
76,676 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 146 ms
76,360 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 145 ms
76,268 KB |
testcase_33 | WA | - |
ソースコード
import heapq class DeletableHeapq: def __init__(self, lst=None, reverse=False): if reverse: self.pm = -1 else: self.pm = 1 if lst is None: self.hq = [] else: self.hq = [self.pm * x for x in lst] heapq.heapify(self.hq) self.tot = sum(self.hq) * self.pm self.cnt = {} for x in self.hq: self.cnt[x] = self.cnt.get(x, 0) + 1 self.length = len(self.hq) def __bool__(self): return bool(self.hq) def __len__(self): return self.length @property def sum(self): return self.tot def top(self): if self.hq: return self.hq[0] * self.pm else: return None def __getitem__(self, i): # 先頭要素にアクセスしたいときのみ assert i == 0 return self.top() def push(self, x): self.length += 1 self.cnt[x * self.pm] = self.cnt.get(x * self.pm, 0) + 1 self.tot += x heapq.heappush(self.hq, x * self.pm) def pop(self): if not self.hq: return None self.length -= 1 x = heapq.heappop(self.hq) self.cnt[x] -= 1 self.tot -= x * self.pm self._delete() return x * self.pm def remove(self, x): if self.cnt.get(x * self.pm, 0) == 0: return False self.length -= 1 self.cnt[x * self.pm] -= 1 self.tot -= x self._delete() return True def _delete(self): while self.hq and self.cnt.get(self.hq[0], 0) == 0: heapq.heappop(self.hq) n, Q = map(int, input().split()) hq1 = DeletableHeapq() hq2 = DeletableHeapq() S = [""] * 4001 tf = [False] * 10000 dic = {} for _ in range(Q): query = input().split() if query[0] == "1": s, r = query[1:] r = int(r) S[r] = s dic[s] = r hq1.push(r) tf[r] = True elif query[0] == "2": x = int(query[1]) n -= x else: s, x = query[1:] x = int(x) n += x r = dic[s] if tf[r]: tf[r] = False hq1.remove(r) hq2.push(r) while n < len(hq1) + len(hq2): if hq1: r = hq1.pop() print(S[r]) else: r = hq2.pop() print(S[r])