結果

問題 No.649 ここでちょっとQK!
ユーザー 双六双六
提出日時 2020-08-11 20:03:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,650 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 81,408 KB
最終ジャッジ日時 2024-04-17 17:32:28
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
58,368 KB
testcase_01 AC 51 ms
58,240 KB
testcase_02 RE -
testcase_03 AC 124 ms
80,896 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 51 ms
58,624 KB
testcase_08 RE -
testcase_09 AC 59 ms
64,768 KB
testcase_10 AC 57 ms
64,000 KB
testcase_11 AC 56 ms
64,000 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 79 ms
75,392 KB
testcase_28 AC 80 ms
75,264 KB
testcase_29 AC 75 ms
71,808 KB
testcase_30 AC 228 ms
81,408 KB
testcase_31 AC 185 ms
81,408 KB
testcase_32 AC 52 ms
58,240 KB
testcase_33 AC 51 ms
58,112 KB
testcase_34 RE -
testcase_35 AC 50 ms
57,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	# k番目の値を取得
	def pointQuery(self, k):
		return self.data[k + self.N0 - 1]

	# k番目の値にxを加算
	def add(self, k, x):
		k += self.N0 - 1
		self.data[k] += x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

def Binary_Search(Seg, K):
	#初期化
	left = 0
	right = 2 * (10 ** 5)
	itr = INF
	
	#二分探索
	while left <= right:
		mid = (left + right) // 2
		if Seg.query(0, mid) < K:
			left = mid + 1
		else:
			itr = min(itr, mid)
			right = mid - 1

	return itr

#処理内容
def main():
	Q, K = getlist()
	val = 0
	Seg = SegmentTree(2 * (10 ** 5) + 1)
	for i in range(Q):
		q = getlist()
		if q[0] == 1:
			val += 1
			x = q[1]
			Seg.add(x, 1)
		else:
			if val < K:
				print(-1)
			else:
				itr = Binary_Search(Seg, K)
				print(itr)
				Seg.add(itr, -1)
				val -= 1


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