結果

問題 No.2804 Fixer And Ratism
ユーザー ra5anchor
提出日時 2024-07-13 19:30:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,172 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 77,460 KB
最終ジャッジ日時 2024-07-13 19:30:16
合計ジャッジ時間 14,106 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

# from sortedcontainers import SortedSet, SortedList, SortedDict
# S1 = SortedList([])
# S2 = SortedList([])

S1 = []
S2 = []

N, Q = map(int, input().split())
now = N

rate = dict()
out = []

for q in range(Q):
    L = list(map(str, input().split()))
    if L[0] == '1':
        s, r = L[1], int(L[2])
        # レートr、名前sが来る
        rate[s] = r
        # S2.add((r, s))
        S2.append((r, s))

    elif L[0] == '2':
        x = int(L[1])
        # x個のpcが壊れる
        now -= x

    elif L[0] == '3':
        s, x = L[1], int(L[2])
        # 名前sがx個を治す
        now += x
        
        if (rate[s], s) in S2:
            S2.remove((rate[s], s))
            S1.append((rate[s], s))
        # S2.discard((s, rate[s]))
        # S1.add((s, rate[s]))

    # 退場
    N1 = len(S1)
    N2 = len(S2)
    Ntot = N1 + N2
    Nout = Ntot - now
    outnow = []
    outN2 = min(Nout, N2)
    outN1 = Nout - outN2
    S1.sort(reverse=True)
    S2.sort(reverse=True)
    for i in range(outN2):
        a = S2.pop()
        outnow.append(a)
    for i in range(outN1):
        a = S1.pop()
        outnow.append(a)
    outnow.sort()
    for r,s in outnow:
        out.append(s)

for item in out:
    print(item)
0