結果

問題 No.649 ここでちょっとQK!
ユーザー tamatotamato
提出日時 2020-05-04 12:39:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 483 ms / 3,000 ms
コード長 1,595 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 87,592 KB
実行使用メモリ 185,080 KB
最終ジャッジ日時 2023-09-06 07:01:50
合計ジャッジ時間 12,994 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,916 KB
testcase_01 AC 70 ms
71,872 KB
testcase_02 AC 70 ms
71,720 KB
testcase_03 AC 175 ms
103,588 KB
testcase_04 AC 300 ms
185,080 KB
testcase_05 AC 300 ms
184,944 KB
testcase_06 AC 229 ms
103,668 KB
testcase_07 AC 67 ms
71,924 KB
testcase_08 AC 67 ms
71,916 KB
testcase_09 AC 69 ms
71,532 KB
testcase_10 AC 69 ms
71,788 KB
testcase_11 AC 71 ms
71,896 KB
testcase_12 AC 272 ms
125,920 KB
testcase_13 AC 280 ms
125,632 KB
testcase_14 AC 276 ms
125,992 KB
testcase_15 AC 288 ms
125,824 KB
testcase_16 AC 271 ms
126,020 KB
testcase_17 AC 299 ms
132,700 KB
testcase_18 AC 323 ms
135,892 KB
testcase_19 AC 340 ms
146,080 KB
testcase_20 AC 366 ms
148,160 KB
testcase_21 AC 375 ms
155,356 KB
testcase_22 AC 396 ms
157,052 KB
testcase_23 AC 427 ms
168,592 KB
testcase_24 AC 437 ms
169,616 KB
testcase_25 AC 459 ms
181,888 KB
testcase_26 AC 483 ms
174,000 KB
testcase_27 AC 83 ms
76,800 KB
testcase_28 AC 80 ms
76,712 KB
testcase_29 AC 80 ms
76,580 KB
testcase_30 AC 246 ms
115,552 KB
testcase_31 AC 231 ms
115,008 KB
testcase_32 AC 68 ms
71,612 KB
testcase_33 AC 72 ms
72,032 KB
testcase_34 AC 69 ms
71,532 KB
testcase_35 AC 69 ms
71,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    Q, K = map(int, input().split())
    query = []
    V = set()
    for _ in range(Q):
        line = list(map(int, input().split()))
        if line[0] == 1:
            V.add(line[1])
        query.append(line)

    V = sorted(list(V))
    v2i = {v: i+1 for i, v in enumerate(V)}
    i2v = {i+1: v for i, v in enumerate(V)}

    N = len(V)
    if N == 0:
        for _ in range(Q):
            print(-1)
        exit()
    bit = Bit(N)
    for q in query:
        if q[0] == 1:
            v = q[1]
            bit.add(v2i[v], 1)
        else:
            j = bit.lower_bound(K)
            if j == N+1:
                print(-1)
            else:
                print(i2v[j])
                bit.add(j, -1)


if __name__ == '__main__':
    main()
0