結果

問題 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,556 ms / 3,000 ms
コード長 2,451 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 40,944 KB
最終ジャッジ日時 2024-09-14 13:17:17
合計ジャッジ時間 45,981 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
11,392 KB
testcase_01 AC 39 ms
11,520 KB
testcase_02 AC 38 ms
11,392 KB
testcase_03 AC 52 ms
11,904 KB
testcase_04 AC 48 ms
11,904 KB
testcase_05 AC 55 ms
11,776 KB
testcase_06 AC 91 ms
12,032 KB
testcase_07 AC 107 ms
11,776 KB
testcase_08 AC 102 ms
11,776 KB
testcase_09 AC 96 ms
11,648 KB
testcase_10 AC 93 ms
11,648 KB
testcase_11 AC 96 ms
11,904 KB
testcase_12 AC 95 ms
11,776 KB
testcase_13 AC 1,008 ms
29,492 KB
testcase_14 AC 730 ms
22,596 KB
testcase_15 AC 805 ms
14,336 KB
testcase_16 AC 975 ms
15,940 KB
testcase_17 AC 703 ms
14,336 KB
testcase_18 AC 584 ms
14,976 KB
testcase_19 AC 1,061 ms
19,808 KB
testcase_20 AC 665 ms
17,692 KB
testcase_21 AC 763 ms
27,016 KB
testcase_22 AC 1,156 ms
31,984 KB
testcase_23 AC 634 ms
11,520 KB
testcase_24 AC 639 ms
11,648 KB
testcase_25 AC 639 ms
11,776 KB
testcase_26 AC 639 ms
11,520 KB
testcase_27 AC 642 ms
11,520 KB
testcase_28 AC 638 ms
11,648 KB
testcase_29 AC 639 ms
11,648 KB
testcase_30 AC 640 ms
11,776 KB
testcase_31 AC 637 ms
11,776 KB
testcase_32 AC 635 ms
11,648 KB
testcase_33 AC 1,539 ms
40,880 KB
testcase_34 AC 1,539 ms
40,944 KB
testcase_35 AC 1,532 ms
40,944 KB
testcase_36 AC 1,533 ms
40,812 KB
testcase_37 AC 1,541 ms
40,896 KB
testcase_38 AC 1,540 ms
40,812 KB
testcase_39 AC 1,549 ms
40,880 KB
testcase_40 AC 1,556 ms
40,816 KB
testcase_41 AC 1,545 ms
40,860 KB
testcase_42 AC 1,525 ms
40,876 KB
testcase_43 AC 813 ms
28,400 KB
testcase_44 AC 795 ms
28,400 KB
testcase_45 AC 792 ms
28,332 KB
testcase_46 AC 817 ms
28,012 KB
testcase_47 AC 793 ms
28,468 KB
testcase_48 AC 809 ms
28,272 KB
testcase_49 AC 1,331 ms
31,984 KB
testcase_50 AC 1,317 ms
32,240 KB
testcase_51 AC 1,332 ms
32,240 KB
testcase_52 AC 1,328 ms
32,112 KB
testcase_53 AC 1,321 ms
32,236 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