結果
問題 | No.2804 Fixer And Ratism |
ユーザー | YuuuT |
提出日時 | 2024-07-12 21:19:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 1,495 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 76,776 KB |
最終ジャッジ日時 | 2024-07-12 21:19:18 |
合計ジャッジ時間 | 5,125 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
# oj t -c "python3 main.py" import sys,math from collections import defaultdict,deque from itertools import combinations,permutations,accumulate,product from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify #from sortedcontainers import SortedList,SortedSet def input():return sys.stdin.readline().rstrip() def ii(): return int(input()) def ms(): return map(int, input().split()) def li(): return list(map(int,input().split())) inf = pow(10,18) mod = 998244353 #////////////////////////////////// N,Q = ms() fix,nofix = [],[] fixed = set() rate = defaultdict(int) for _ in range(Q): f,*s = input().split() if f=="1": s,r = s r = int(r) heappush(nofix,(r,s)) rate[s] = r N -= 1 while N<0: done = False while nofix: _,s = heappop(nofix) if s not in fixed: print(s) done = True break if done==False: _,s = heappop(fix) print(s) N += 1 elif f=="2": x = s[0] x = int(x) N -= x ans = [] while N<0: done = False while nofix: r,s = heappop(nofix) if s not in fixed: heappush(ans,(r,s)) done = True break if done==False: r,s = heappop(fix) heappush(ans,(r,s)) N += 1 while ans: _,s = heappop(ans) print(s) else: s,x = s x = int(x) N += x if s in fixed: continue fixed.add(s) heappush(fix,(rate[s],s))