結果

問題 No.649 ここでちょっとQK!
ユーザー vwxyzvwxyz
提出日時 2022-03-29 13:27:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 891 ms / 3,000 ms
コード長 1,363 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-04-25 15:15:39
合計ジャッジ時間 13,114 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 29 ms
10,880 KB
testcase_03 AC 361 ms
11,264 KB
testcase_04 AC 891 ms
18,816 KB
testcase_05 AC 468 ms
18,816 KB
testcase_06 AC 401 ms
21,888 KB
testcase_07 AC 28 ms
10,880 KB
testcase_08 AC 28 ms
11,008 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 28 ms
11,008 KB
testcase_11 AC 29 ms
11,008 KB
testcase_12 AC 238 ms
14,080 KB
testcase_13 AC 233 ms
14,208 KB
testcase_14 AC 227 ms
14,080 KB
testcase_15 AC 287 ms
14,208 KB
testcase_16 AC 276 ms
14,336 KB
testcase_17 AC 391 ms
14,848 KB
testcase_18 AC 443 ms
14,976 KB
testcase_19 AC 480 ms
15,104 KB
testcase_20 AC 519 ms
15,616 KB
testcase_21 AC 548 ms
16,000 KB
testcase_22 AC 602 ms
16,232 KB
testcase_23 AC 611 ms
16,640 KB
testcase_24 AC 669 ms
16,892 KB
testcase_25 AC 710 ms
17,280 KB
testcase_26 AC 727 ms
17,536 KB
testcase_27 AC 31 ms
10,880 KB
testcase_28 AC 30 ms
10,880 KB
testcase_29 AC 32 ms
11,008 KB
testcase_30 AC 237 ms
14,080 KB
testcase_31 AC 328 ms
14,464 KB
testcase_32 AC 29 ms
10,880 KB
testcase_33 AC 28 ms
10,880 KB
testcase_34 AC 29 ms
10,752 KB
testcase_35 AC 29 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

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)
0