結果

問題 No.649 ここでちょっとQK!
ユーザー convexineqconvexineq
提出日時 2021-03-08 01:57:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 501 ms / 3,000 ms
コード長 1,646 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 171,000 KB
最終ジャッジ日時 2024-04-17 17:58:42
合計ジャッジ時間 9,620 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,864 KB
testcase_01 AC 35 ms
52,608 KB
testcase_02 AC 36 ms
52,608 KB
testcase_03 AC 200 ms
97,408 KB
testcase_04 AC 313 ms
171,000 KB
testcase_05 AC 309 ms
170,624 KB
testcase_06 AC 254 ms
97,408 KB
testcase_07 AC 35 ms
52,224 KB
testcase_08 AC 35 ms
52,480 KB
testcase_09 AC 36 ms
52,864 KB
testcase_10 AC 34 ms
52,096 KB
testcase_11 AC 33 ms
52,608 KB
testcase_12 AC 259 ms
119,296 KB
testcase_13 AC 268 ms
119,416 KB
testcase_14 AC 265 ms
119,736 KB
testcase_15 AC 272 ms
119,040 KB
testcase_16 AC 276 ms
119,168 KB
testcase_17 AC 298 ms
111,056 KB
testcase_18 AC 322 ms
129,056 KB
testcase_19 AC 343 ms
134,272 KB
testcase_20 AC 358 ms
136,648 KB
testcase_21 AC 374 ms
142,080 KB
testcase_22 AC 389 ms
143,744 KB
testcase_23 AC 416 ms
141,824 KB
testcase_24 AC 439 ms
140,672 KB
testcase_25 AC 457 ms
160,784 KB
testcase_26 AC 501 ms
140,680 KB
testcase_27 AC 58 ms
66,432 KB
testcase_28 AC 57 ms
67,072 KB
testcase_29 AC 57 ms
66,560 KB
testcase_30 AC 229 ms
109,056 KB
testcase_31 AC 225 ms
108,676 KB
testcase_32 AC 36 ms
52,736 KB
testcase_33 AC 34 ms
52,224 KB
testcase_34 AC 34 ms
52,480 KB
testcase_35 AC 32 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def range_sum_larger(self,l): #a_l + ... (端まで)
        return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0)
    
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x


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

bit = BIT(len(nums))
zaatu = {ai:i for i, ai in enumerate(sorted(nums))}
nums = sorted(nums)
c = 0
for a in query:
    if a[0]==1:
        bit.add(zaatu[a[1]],1)
        c += 1
    else:
        if c < K:
            print(-1)
        else:
            idx = bit.bisect_left(K)
            print(nums[idx])
            bit.add(idx,-1)
            c -= 1
0