結果

問題 No.2804 Fixer And Ratism
ユーザー ntuda
提出日時 2024-07-13 19:06:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,095 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 82,796 KB
実行使用メモリ 77,388 KB
最終ジャッジ日時 2024-07-13 19:06:19
合計ジャッジ時間 6,606 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 17 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
from collections import defaultdict

N, Q0 = map(int, input().split())
dic1 = defaultdict(int)
dic2 = defaultdict(int)
Q = []
ans = []
upd = set()
for q in range(Q0):
    t, *sr = input().split()
    if t == "1":
        s, r = sr
        r = int(r)
        dic1[s] = r
        dic2[s] = 0
        heappush(Q,(0, r, s))
        tmp = []
        if N + len(upd) < len(Q):
            a, b, s = heappop(Q)
            if a == 0 and (a,b,s) in upd:
                upd.remove((a,b,s))
            ans.append(s)
    elif t == "2":
        x = int(sr[0])
        N = max(0, N - x)
        tmp = []
        while N + len(upd) < len(Q):
            a, b, s = heappop(Q)
            if a == 0 and (a,b,s) in upd:
                upd.remove((a,b,s))
                continue
            tmp.append((b,s))
        tmp.sort()
        for t, s in tmp:
            ans.append(s)
    else:
        s, x = sr
        x = int(x)
        N += x
        if dic2[s] == 0:
            upd.add((0,dic1[s], s))
            heappush(Q,(1,dic1[s],s))
        dic2[s] = 1

for s in ans:
    print(s)
0