結果

問題 No.2804 Fixer And Ratism
ユーザー rin204
提出日時 2024-07-12 21:16:41
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 857 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 65,152 KB
最終ジャッジ日時 2024-07-12 21:16:58
合計ジャッジ時間 4,110 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from src.misc.DeletableHeapq import DeletableHeapq

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])
0