結果

問題 No.1705 Mode of long array
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-10-10 17:41:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 710 ms / 3,000 ms
コード長 2,451 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 103,984 KB
最終ジャッジ日時 2023-10-12 14:24:02
合計ジャッジ時間 27,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
80,312 KB
testcase_01 AC 176 ms
80,336 KB
testcase_02 AC 174 ms
80,032 KB
testcase_03 AC 246 ms
82,928 KB
testcase_04 AC 234 ms
83,068 KB
testcase_05 AC 254 ms
83,436 KB
testcase_06 AC 314 ms
84,172 KB
testcase_07 AC 328 ms
84,464 KB
testcase_08 AC 311 ms
84,220 KB
testcase_09 AC 304 ms
83,816 KB
testcase_10 AC 307 ms
84,564 KB
testcase_11 AC 331 ms
84,980 KB
testcase_12 AC 308 ms
84,500 KB
testcase_13 AC 680 ms
98,688 KB
testcase_14 AC 615 ms
93,812 KB
testcase_15 AC 582 ms
88,788 KB
testcase_16 AC 651 ms
91,652 KB
testcase_17 AC 550 ms
88,808 KB
testcase_18 AC 547 ms
89,524 KB
testcase_19 AC 697 ms
93,668 KB
testcase_20 AC 585 ms
90,636 KB
testcase_21 AC 592 ms
96,704 KB
testcase_22 AC 710 ms
102,644 KB
testcase_23 AC 323 ms
82,840 KB
testcase_24 AC 330 ms
83,012 KB
testcase_25 AC 328 ms
83,064 KB
testcase_26 AC 328 ms
82,844 KB
testcase_27 AC 332 ms
83,024 KB
testcase_28 AC 324 ms
83,128 KB
testcase_29 AC 332 ms
83,632 KB
testcase_30 AC 333 ms
83,584 KB
testcase_31 AC 325 ms
82,892 KB
testcase_32 AC 334 ms
83,668 KB
testcase_33 AC 500 ms
103,464 KB
testcase_34 AC 507 ms
103,636 KB
testcase_35 AC 483 ms
103,524 KB
testcase_36 AC 506 ms
103,820 KB
testcase_37 AC 531 ms
103,804 KB
testcase_38 AC 521 ms
103,832 KB
testcase_39 AC 521 ms
103,416 KB
testcase_40 AC 497 ms
103,548 KB
testcase_41 AC 484 ms
103,932 KB
testcase_42 AC 502 ms
103,596 KB
testcase_43 AC 464 ms
103,620 KB
testcase_44 AC 485 ms
103,680 KB
testcase_45 AC 483 ms
103,692 KB
testcase_46 AC 474 ms
103,912 KB
testcase_47 AC 496 ms
103,736 KB
testcase_48 AC 493 ms
103,984 KB
testcase_49 AC 620 ms
103,440 KB
testcase_50 AC 627 ms
103,636 KB
testcase_51 AC 601 ms
103,424 KB
testcase_52 AC 619 ms
103,368 KB
testcase_53 AC 594 ms
103,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import typing

class SegmentTree:
	def __init__(
			self, 
			lis: list, 
			ele: typing.Any, 
			op: typing.Callable[[typing.Any, typing.Any], typing.Any]) -> None:
		self.n = len(lis)
		self.log = (self.n - 1).bit_length()
		self.size = 1 << self.log
		self.op = op
		self.ele = ele
		self.tree = self._build(lis)

	def _build(self, lis: list) -> list:
		res_tree = [self.ele] * (2 * self.size)
		for i, a in enumerate(lis):
			res_tree[self.size + i] = a
		for i in range(1, self.size)[::-1]:
			res_tree[i] = self.op(res_tree[2 * i], res_tree[2 * i + 1])
		return res_tree

	def __getitem__(self, i: int) -> None:
		return self.tree[self.size + i]

	def __setitem__(self, p: int, x: int) -> None:
		p += self.size
		self.tree[p] = x
		for i in range(1, self.log + 1):
			self.tree[p >> i] = self.op(self.tree[2 * (p >> i)], self.tree[2 * (p >> i) + 1])

	def prod(self, l: int, r: int) -> typing.Any:
		l += self.size
		r += self.size
		L = R = self.ele
		while l < r:
			if l & 1:
				L = self.op(L, self.tree[l])
				l += 1
			if r & 1:
				r -= 1
				R = self.op(self.tree[r], R)
			l >>= 1
			r >>= 1
		return self.op(L, R)

	def all_prod(self) -> typing.Any:
		return self.tree[1]

	def max_right(self, l: int, f) -> int:
		if l == self.n:
			return self.n
		l += self.size
		sm = self.ele
		while True:
			while l % 2 == 0:
				l >>= 1
			if not f(self.op(sm, self.tree[l])):
				while l < self.size:
					l *= 2
					if f(self.op(sm, self.tree[l])):
						sm = self.op(sm, self.tree[l])
						l += 1
				return l - self.size
			sm = self.op(sm, self.tree[l])
			l += 1
			if (l & -l) == l:
				return self.n

	def min_left(self, r: int, f) -> int:
		if r == 0:
			return 0
		r += self.size
		sm = self.ele
		while True:
			r -= 1
			while r > 1 and (r % 2):
				r >>= 1
			if not f(self.op(self.tree[r], sm)):
				while r < self.size:
					r = 2 * r + 1
					if f(self.op(self.tree[r], sm)):
						sm = self.op(self.tree[r], sm)
						r -= 1
				return r + 1 - self.size
			sm = self.op(self.d[r], sm)
			if (r & -r) == r:
				return 0

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [(a[i], i + 1) for i in range(m)]
def op(a, b):
	return a if a[0] > b[0] else b
ST = SegmentTree(a, [-1, -1], op)
for _ in range(int(input())):
	t, x, y = map(int, input().split())
	if t == 1: ST[x - 1] = [ST[x - 1][0] + y, ST[x - 1][1]]
	if t == 2: ST[x - 1] = [ST[x - 1][0] - y, ST[x - 1][1]]
	if t == 3: print(ST.all_prod()[1])
0