結果
問題 | No.2804 Fixer And Ratism |
ユーザー | 👑 rin204 |
提出日時 | 2024-07-12 21:17:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 2,470 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 76,792 KB |
最終ジャッジ日時 | 2024-07-12 21:17:20 |
合計ジャッジ時間 | 5,516 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,612 KB |
testcase_01 | AC | 35 ms
53,080 KB |
testcase_02 | AC | 36 ms
53,480 KB |
testcase_03 | AC | 92 ms
76,792 KB |
testcase_04 | AC | 92 ms
76,676 KB |
testcase_05 | AC | 81 ms
76,460 KB |
testcase_06 | AC | 132 ms
76,464 KB |
testcase_07 | AC | 87 ms
76,320 KB |
testcase_08 | AC | 83 ms
76,348 KB |
testcase_09 | AC | 70 ms
74,476 KB |
testcase_10 | AC | 78 ms
76,276 KB |
testcase_11 | AC | 107 ms
76,356 KB |
testcase_12 | AC | 104 ms
76,276 KB |
testcase_13 | AC | 77 ms
76,312 KB |
testcase_14 | AC | 104 ms
76,408 KB |
testcase_15 | AC | 71 ms
74,440 KB |
testcase_16 | AC | 111 ms
76,304 KB |
testcase_17 | AC | 84 ms
76,508 KB |
testcase_18 | AC | 128 ms
76,348 KB |
testcase_19 | AC | 64 ms
72,152 KB |
testcase_20 | AC | 78 ms
76,284 KB |
testcase_21 | AC | 128 ms
76,324 KB |
testcase_22 | AC | 67 ms
72,732 KB |
testcase_23 | AC | 157 ms
76,520 KB |
testcase_24 | AC | 155 ms
76,528 KB |
testcase_25 | AC | 143 ms
76,332 KB |
testcase_26 | AC | 145 ms
76,296 KB |
testcase_27 | AC | 145 ms
76,308 KB |
testcase_28 | AC | 143 ms
76,560 KB |
testcase_29 | AC | 140 ms
76,548 KB |
testcase_30 | AC | 144 ms
76,460 KB |
testcase_31 | AC | 140 ms
76,452 KB |
testcase_32 | AC | 140 ms
76,748 KB |
testcase_33 | AC | 36 ms
53,076 KB |
ソースコード
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) ans = [] while n < len(hq1) + len(hq2): if hq1: r = hq1.pop() ans.append(r) else: r = hq2.pop() ans.append(r) ans.sort() for r in ans: print(S[r])