結果

問題 No.649 ここでちょっとQK!
ユーザー ああいいああいい
提出日時 2022-01-09 22:53:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 462 ms / 3,000 ms
コード長 844 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 167,656 KB
最終ジャッジ日時 2024-04-26 19:55:57
合計ジャッジ時間 9,502 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,480 KB
testcase_01 AC 38 ms
51,712 KB
testcase_02 AC 37 ms
52,224 KB
testcase_03 AC 120 ms
83,600 KB
testcase_04 AC 279 ms
167,656 KB
testcase_05 AC 282 ms
167,420 KB
testcase_06 AC 181 ms
85,068 KB
testcase_07 AC 38 ms
51,840 KB
testcase_08 AC 39 ms
52,224 KB
testcase_09 AC 39 ms
52,096 KB
testcase_10 AC 38 ms
51,968 KB
testcase_11 AC 38 ms
51,712 KB
testcase_12 AC 254 ms
116,744 KB
testcase_13 AC 252 ms
117,108 KB
testcase_14 AC 243 ms
116,976 KB
testcase_15 AC 259 ms
117,380 KB
testcase_16 AC 259 ms
117,260 KB
testcase_17 AC 280 ms
122,992 KB
testcase_18 AC 305 ms
128,308 KB
testcase_19 AC 330 ms
134,536 KB
testcase_20 AC 349 ms
136,504 KB
testcase_21 AC 364 ms
145,192 KB
testcase_22 AC 390 ms
144,560 KB
testcase_23 AC 402 ms
151,856 KB
testcase_24 AC 415 ms
139,732 KB
testcase_25 AC 437 ms
166,860 KB
testcase_26 AC 462 ms
144,828 KB
testcase_27 AC 52 ms
63,232 KB
testcase_28 AC 49 ms
62,976 KB
testcase_29 AC 50 ms
62,080 KB
testcase_30 AC 200 ms
103,496 KB
testcase_31 AC 222 ms
105,424 KB
testcase_32 AC 40 ms
51,968 KB
testcase_33 AC 39 ms
52,224 KB
testcase_34 AC 40 ms
51,840 KB
testcase_35 AC 40 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
r = sys.stdin
Q,K = map(int,r.readline().split())

l = []
s = set()
for _ in range(Q):
    a = list(map(int,r.readline().split()))
    if a[0] == 1:
        l.append(a[1])
        s.add(a[1])
    else:
        l.append(-2)
D = {v:i+1 for i,v in enumerate(sorted(s))}
rD = {i+1:v for i,v in enumerate(sorted(s))}

n = len(D)
bit = [0] * (n +1)
def add(i,x):
    while i <= n:
        bit[i] += x
        i += i &-i
def lb(w):
    if w <= 0:return 0
    k = 1
    while k <= n:
        k <<= 1
    k >>= 1
    x = 0
    while k > 0:
        if x + k <= n and bit[x+k] < w:
            w -= bit[x+k]
            x += k
        k >>= 1
    return x + 1

for v in l:
    if v != -2:
        add(D[v],1)
    else:
        x = lb(K)
        if x == n + 1:
            print(-1)
        else:
            print(rD[x])
            add(x,-1)

0