結果

問題 No.649 ここでちょっとQK!
ユーザー 双六双六
提出日時 2020-08-11 20:09:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 420 ms / 3,000 ms
コード長 1,930 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 185,004 KB
最終ジャッジ日時 2024-04-17 17:32:54
合計ジャッジ時間 8,059 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
57,984 KB
testcase_01 AC 35 ms
58,112 KB
testcase_02 AC 34 ms
58,368 KB
testcase_03 AC 141 ms
106,624 KB
testcase_04 AC 235 ms
185,004 KB
testcase_05 AC 230 ms
185,004 KB
testcase_06 AC 189 ms
116,096 KB
testcase_07 AC 39 ms
58,240 KB
testcase_08 AC 37 ms
58,368 KB
testcase_09 AC 42 ms
64,640 KB
testcase_10 AC 41 ms
64,768 KB
testcase_11 AC 39 ms
64,128 KB
testcase_12 AC 247 ms
124,780 KB
testcase_13 AC 236 ms
124,484 KB
testcase_14 AC 252 ms
125,148 KB
testcase_15 AC 245 ms
124,968 KB
testcase_16 AC 211 ms
124,572 KB
testcase_17 AC 238 ms
131,200 KB
testcase_18 AC 262 ms
135,800 KB
testcase_19 AC 279 ms
142,464 KB
testcase_20 AC 296 ms
142,080 KB
testcase_21 AC 319 ms
152,064 KB
testcase_22 AC 339 ms
153,472 KB
testcase_23 AC 358 ms
136,960 KB
testcase_24 AC 379 ms
163,300 KB
testcase_25 AC 396 ms
173,520 KB
testcase_26 AC 420 ms
179,756 KB
testcase_27 AC 58 ms
75,776 KB
testcase_28 AC 57 ms
75,264 KB
testcase_29 AC 52 ms
72,192 KB
testcase_30 AC 209 ms
115,424 KB
testcase_31 AC 185 ms
115,072 KB
testcase_32 AC 37 ms
58,624 KB
testcase_33 AC 36 ms
57,856 KB
testcase_34 AC 36 ms
58,368 KB
testcase_35 AC 39 ms
57,728 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)

	query = []
	compress = []
	for i in range(Q):
		q = getlist()
		query.append(q)
		if q[0] == 1:
			compress.append(q[1])

	# 座圧
	compress = list(sorted(list(set(compress))))
	convD = defaultdict(int)
	for i in range(len(compress)):
		convD[compress[i]] = i

	for i in range(Q):
		q = query[i]
		if q[0] == 1:
			val += 1
			x = convD[q[1]]
			Seg.add(x, 1)
		else:
			if val < K:
				print(-1)
			else:
				itr = Binary_Search(Seg, K)
				print(compress[itr])
				Seg.add(itr, -1)
				val -= 1


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