結果
問題 | No.649 ここでちょっとQK! |
ユーザー | vwxyz |
提出日時 | 2022-03-29 13:27:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 278 ms / 3,000 ms |
コード長 | 1,363 bytes |
コンパイル時間 | 290 ms |
コンパイル使用メモリ | 82,456 KB |
実行使用メモリ | 84,880 KB |
最終ジャッジ日時 | 2024-04-25 15:15:46 |
合計ジャッジ時間 | 6,667 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,492 KB |
testcase_01 | AC | 37 ms
53,320 KB |
testcase_02 | AC | 37 ms
54,528 KB |
testcase_03 | AC | 94 ms
76,560 KB |
testcase_04 | AC | 206 ms
84,760 KB |
testcase_05 | AC | 131 ms
82,508 KB |
testcase_06 | AC | 139 ms
81,800 KB |
testcase_07 | AC | 36 ms
54,040 KB |
testcase_08 | AC | 37 ms
54,496 KB |
testcase_09 | AC | 35 ms
53,752 KB |
testcase_10 | AC | 36 ms
53,184 KB |
testcase_11 | AC | 38 ms
53,688 KB |
testcase_12 | AC | 164 ms
80,388 KB |
testcase_13 | AC | 144 ms
80,640 KB |
testcase_14 | AC | 151 ms
80,852 KB |
testcase_15 | AC | 215 ms
82,036 KB |
testcase_16 | AC | 177 ms
79,472 KB |
testcase_17 | AC | 211 ms
80,724 KB |
testcase_18 | AC | 215 ms
80,620 KB |
testcase_19 | AC | 228 ms
81,688 KB |
testcase_20 | AC | 231 ms
82,408 KB |
testcase_21 | AC | 234 ms
82,412 KB |
testcase_22 | AC | 243 ms
82,876 KB |
testcase_23 | AC | 258 ms
83,512 KB |
testcase_24 | AC | 262 ms
83,716 KB |
testcase_25 | AC | 270 ms
84,720 KB |
testcase_26 | AC | 278 ms
84,880 KB |
testcase_27 | AC | 47 ms
61,968 KB |
testcase_28 | AC | 50 ms
63,100 KB |
testcase_29 | AC | 52 ms
64,024 KB |
testcase_30 | AC | 180 ms
80,728 KB |
testcase_31 | AC | 195 ms
79,740 KB |
testcase_32 | AC | 39 ms
53,416 KB |
testcase_33 | AC | 36 ms
54,360 KB |
testcase_34 | AC | 36 ms
53,228 KB |
testcase_35 | AC | 37 ms
53,816 KB |
ソースコード
import heapq import sys from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item readline=sys.stdin.readline class Slope_Trick: def __init__(self): self.queueL=[] self.queueR=[] def Push_Left(self,x): _heappush_max(self.queueL,heappushpop(self.queueR,x)) def Push_Right(self,x): heappush(self.queueR,_heappushpop_max(self.queueL,x)) def Pop_Left(self): return _heappop_max(self.queueL) def Pop_Right(self): return heappop(self.queueR) def __str__(self): return '['+', '.join(map(str,sorted(self.queueL)))+']+['+', '.join(map(str,sorted(self.queueR)))+']' Q,K=map(int,readline().split()) ST=Slope_Trick() for _ in range(Q): data=map(int,readline().split()) q=next(data) if q==1: v=next(data) if len(ST.queueL)<K: ST.Push_Left(v) else: ST.Push_Right(v) else: if len(ST.queueL)==K: ans=ST.Pop_Left() if ST.queueR: ST.Push_Left(ST.Pop_Right()) else: ans=-1 print(ans)