結果
問題 | No.1234 典型RMQ |
ユーザー | c-yan |
提出日時 | 2021-02-07 01:44:48 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,945 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 32,908 KB |
最終ジャッジ日時 | 2024-07-03 13:37:29 |
合計ジャッジ時間 | 5,865 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
18,080 KB |
testcase_01 | AC | 30 ms
11,008 KB |
testcase_02 | AC | 30 ms
11,008 KB |
testcase_03 | AC | 30 ms
11,008 KB |
testcase_04 | AC | 30 ms
11,136 KB |
testcase_05 | AC | 30 ms
11,008 KB |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
ソースコード
from sys import stdin, setrecursionlimit class SegmentTree: DEFAULT_VALUE = 10 ** 18 op = min def __init__(self, size): self._size = size t = 1 while t < size: t *= 2 self._offset = t - 1 self._values = [SegmentTree.DEFAULT_VALUE] * (t * 2 - 1) self._lazy = [None] * (t * 2 - 1) def build(self, iterable): op = SegmentTree.op values = self._values values[self._offset:self._offset + self._size] = iterable for i in range(self._offset - 1, -1, -1): values[i] = SegmentTree.op(values[i * 2 + 1], values[i * 2 + 2]) def _iter_segmen_indexes(self, start, stop): l = start + self._offset r = stop + self._offset while l < r: if l & 1 == 0: yield l if r & 1 == 0: yield r - 1 l = l // 2 r = (r - 1) // 2 def _propagate_to(self, index, value): if self._lazy[index] is None: self._lazy[index] = value else: self._lazy[index] += value self._values[index] += value def _propagate_at(self, index): if index != 0: self._propagate_at((index - 1) // 2) lazy = self._lazy[index] if lazy is None: return self._propagate_to(index * 2 + 1, lazy) self._propagate_to(index * 2 + 2, lazy) self._lazy[index] = None def _propagate(self, start, stop): for i in self._iter_segmen_indexes(start, stop): if i != 0: self._propagate_at((i - 1) // 2) def _recalc_at(self, index): self._values[index] = SegmentTree.op( self._values[index * 2 + 1], self._values[index * 2 + 2]) if index != 0: self._recalc_at((index - 1) // 2) def _apply_to(self, index, value): if self._lazy[index] is None: self._lazy[index] = value else: self._lazy[index] += value self._values[index] += value if index != 0: self._recalc_at((index - 1) // 2) def apply(self, start, stop, value): self._propagate(start, stop) for i in self._iter_segmen_indexes(start, stop): self._apply_to(i, value) def query(self, start, stop): self._propagate(start, stop) values = self._values result = SegmentTree.DEFAULT_VALUE for i in self._iter_segmen_indexes(start, stop): result = SegmentTree.op(result, values[i]) return result readline = stdin.readline setrecursionlimit(10 ** 6) N = int(readline()) a = list(map(int, readline().split())) Q = int(readline()) st = SegmentTree(N) st.build(a) result = [] for _ in range(Q): k, l, r, c = map(int, readline().split()) if k == 1: st.apply(l - 1, r, c) elif k == 2: result.append(st.query(l - 1, r)) print(*result, sep='\n')