結果

問題 No.1705 Mode of long array
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-10-10 17:40:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,314 ms / 3,000 ms
コード長 2,451 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 11,332 KB
実行使用メモリ 39,260 KB
最終ジャッジ日時 2023-10-12 14:23:33
合計ジャッジ時間 40,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
9,988 KB
testcase_01 AC 33 ms
10,056 KB
testcase_02 AC 31 ms
10,076 KB
testcase_03 AC 43 ms
10,180 KB
testcase_04 AC 41 ms
10,224 KB
testcase_05 AC 47 ms
10,112 KB
testcase_06 AC 80 ms
10,264 KB
testcase_07 AC 95 ms
10,192 KB
testcase_08 AC 93 ms
10,168 KB
testcase_09 AC 84 ms
10,056 KB
testcase_10 AC 80 ms
10,072 KB
testcase_11 AC 84 ms
10,236 KB
testcase_12 AC 84 ms
10,216 KB
testcase_13 AC 865 ms
27,868 KB
testcase_14 AC 638 ms
20,804 KB
testcase_15 AC 703 ms
12,768 KB
testcase_16 AC 851 ms
14,140 KB
testcase_17 AC 624 ms
12,924 KB
testcase_18 AC 498 ms
13,220 KB
testcase_19 AC 994 ms
18,036 KB
testcase_20 AC 593 ms
15,768 KB
testcase_21 AC 647 ms
25,332 KB
testcase_22 AC 988 ms
30,152 KB
testcase_23 AC 593 ms
10,144 KB
testcase_24 AC 594 ms
10,032 KB
testcase_25 AC 589 ms
10,020 KB
testcase_26 AC 590 ms
9,972 KB
testcase_27 AC 591 ms
9,992 KB
testcase_28 AC 587 ms
9,988 KB
testcase_29 AC 593 ms
10,124 KB
testcase_30 AC 592 ms
10,016 KB
testcase_31 AC 586 ms
10,016 KB
testcase_32 AC 587 ms
10,048 KB
testcase_33 AC 1,306 ms
39,124 KB
testcase_34 AC 1,293 ms
39,136 KB
testcase_35 AC 1,282 ms
39,200 KB
testcase_36 AC 1,311 ms
39,164 KB
testcase_37 AC 1,291 ms
39,260 KB
testcase_38 AC 1,300 ms
39,200 KB
testcase_39 AC 1,300 ms
39,208 KB
testcase_40 AC 1,305 ms
39,236 KB
testcase_41 AC 1,286 ms
39,168 KB
testcase_42 AC 1,314 ms
39,128 KB
testcase_43 AC 725 ms
26,568 KB
testcase_44 AC 722 ms
26,568 KB
testcase_45 AC 708 ms
26,476 KB
testcase_46 AC 722 ms
26,636 KB
testcase_47 AC 717 ms
26,468 KB
testcase_48 AC 719 ms
26,472 KB
testcase_49 AC 1,151 ms
30,440 KB
testcase_50 AC 1,159 ms
30,456 KB
testcase_51 AC 1,169 ms
30,608 KB
testcase_52 AC 1,153 ms
30,564 KB
testcase_53 AC 1,153 ms
30,552 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