結果

問題 No.649 ここでちょっとQK!
ユーザー vwxyzvwxyz
提出日時 2022-03-19 19:12:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,039 ms / 3,000 ms
コード長 1,022 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-04-15 09:12:56
合計ジャッジ時間 16,129 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,008 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 385 ms
11,008 KB
testcase_04 AC 743 ms
18,816 KB
testcase_05 AC 1,039 ms
18,688 KB
testcase_06 AC 569 ms
21,888 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 31 ms
10,880 KB
testcase_09 AC 32 ms
10,880 KB
testcase_10 AC 32 ms
10,880 KB
testcase_11 AC 32 ms
10,880 KB
testcase_12 AC 420 ms
14,208 KB
testcase_13 AC 378 ms
14,080 KB
testcase_14 AC 382 ms
13,952 KB
testcase_15 AC 507 ms
14,208 KB
testcase_16 AC 288 ms
14,336 KB
testcase_17 AC 416 ms
14,464 KB
testcase_18 AC 454 ms
14,848 KB
testcase_19 AC 533 ms
15,232 KB
testcase_20 AC 574 ms
15,488 KB
testcase_21 AC 642 ms
15,872 KB
testcase_22 AC 665 ms
16,236 KB
testcase_23 AC 763 ms
16,512 KB
testcase_24 AC 797 ms
16,740 KB
testcase_25 AC 860 ms
17,152 KB
testcase_26 AC 926 ms
17,408 KB
testcase_27 AC 35 ms
11,008 KB
testcase_28 AC 34 ms
10,880 KB
testcase_29 AC 35 ms
10,880 KB
testcase_30 AC 453 ms
14,080 KB
testcase_31 AC 349 ms
14,336 KB
testcase_32 AC 31 ms
10,880 KB
testcase_33 AC 31 ms
10,880 KB
testcase_34 AC 32 ms
10,880 KB
testcase_35 AC 32 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

Q,K=map(int,readline().split())
queue0,queue1=[],[]
for _ in range(Q):
    data=map(int,readline().split())
    if next(data)==1:
        v=next(data)
        if len(queue0)<K:
            _heappush_max(queue0,v)
        else:
            heappush(queue1,v)
            x=_heappop_max(queue0)
            y=heappop(queue1)
            if x>y:
                x,y=y,x
            _heappush_max(queue0,x)
            heappush(queue1,y)
    else:
        if len(queue0)<K:
            ans=-1
        else:
            ans=_heappop_max(queue0)
            if queue1:
                _heappush_max(queue0,heappop(queue1))
        print(ans)
0