結果

問題 No.875 Range Mindex Query
ユーザー 双六双六
提出日時 2020-08-04 01:15:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,081 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 106,384 KB
最終ジャッジ日時 2023-10-11 21:40:12
合計ジャッジ時間 12,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,220 KB
testcase_01 AC 130 ms
77,612 KB
testcase_02 AC 135 ms
77,628 KB
testcase_03 AC 103 ms
76,140 KB
testcase_04 AC 116 ms
77,148 KB
testcase_05 AC 106 ms
76,688 KB
testcase_06 AC 123 ms
77,424 KB
testcase_07 AC 129 ms
77,408 KB
testcase_08 AC 119 ms
77,408 KB
testcase_09 AC 120 ms
77,328 KB
testcase_10 AC 140 ms
77,684 KB
testcase_11 AC 1,074 ms
102,456 KB
testcase_12 AC 949 ms
100,108 KB
testcase_13 AC 853 ms
104,716 KB
testcase_14 AC 845 ms
102,764 KB
testcase_15 AC 1,081 ms
106,384 KB
testcase_16 AC 710 ms
104,624 KB
testcase_17 AC 737 ms
105,448 KB
testcase_18 AC 728 ms
105,304 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 = [INF, INF]
		self.data = [self.initVal] * (2 * self.N0)

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

	# セグメント木の中身をリストAで初期化
	def initialize(self, A):
		for i in range(self.N):
			self.data[self.N0 - 1 + i] = A[i]
		for i in range(self.N0 - 2, -1, -1):
			self.data[i] = self.calc(self.data[2 * i + 1], self.data[2 * i + 2])

	#k番目の値をxに更新
	def update(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 main():
	N, Q = getlist()
	A = getlist()
	Seg = SegmentTree(N)
	B = [[A[i], i] for i in range(N)]
	Seg.initialize(B)
	for i in range(Q):
		q = getlist()
		v, l, r = q
		l -= 1; r -= 1
		if v == 1:
			al, litr = Seg.query(l, l)
			ar, ritr = Seg.query(r, r)
			Seg.update(l, [ar, litr])
			Seg.update(r, [al, ritr])

		else:
			ans = Seg.query(l, r)
			print(ans[1] + 1)

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