結果
問題 | No.1234 典型RMQ |
ユーザー | c-yan |
提出日時 | 2021-02-08 22:11:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,734 ms / 2,000 ms |
コード長 | 2,682 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,832 KB |
実行使用メモリ | 101,280 KB |
最終ジャッジ日時 | 2024-07-06 01:35:16 |
合計ジャッジ時間 | 33,129 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
52,836 KB |
testcase_01 | AC | 34 ms
53,988 KB |
testcase_02 | AC | 36 ms
53,212 KB |
testcase_03 | AC | 33 ms
53,380 KB |
testcase_04 | AC | 32 ms
52,960 KB |
testcase_05 | AC | 33 ms
52,580 KB |
testcase_06 | AC | 1,468 ms
101,280 KB |
testcase_07 | AC | 1,348 ms
94,864 KB |
testcase_08 | AC | 1,526 ms
100,620 KB |
testcase_09 | AC | 1,564 ms
96,412 KB |
testcase_10 | AC | 1,734 ms
100,576 KB |
testcase_11 | AC | 1,453 ms
99,376 KB |
testcase_12 | AC | 1,588 ms
98,252 KB |
testcase_13 | AC | 1,309 ms
94,436 KB |
testcase_14 | AC | 1,492 ms
96,548 KB |
testcase_15 | AC | 1,356 ms
95,912 KB |
testcase_16 | AC | 1,471 ms
99,208 KB |
testcase_17 | AC | 1,462 ms
96,444 KB |
testcase_18 | AC | 1,284 ms
94,312 KB |
testcase_19 | AC | 1,597 ms
99,064 KB |
testcase_20 | AC | 874 ms
92,992 KB |
testcase_21 | AC | 1,494 ms
100,168 KB |
testcase_22 | AC | 1,308 ms
95,492 KB |
testcase_23 | AC | 1,483 ms
95,884 KB |
testcase_24 | AC | 1,282 ms
95,556 KB |
testcase_25 | AC | 1,294 ms
96,496 KB |
testcase_26 | AC | 1,298 ms
97,176 KB |
testcase_27 | AC | 32 ms
52,820 KB |
testcase_28 | AC | 32 ms
52,824 KB |
testcase_29 | AC | 34 ms
54,288 KB |
ソースコード
from sys import stdin class SegmentTree: DEFAULT_VALUE = 10 ** 18 DEFAULT_LAZY = 0 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 = [SegmentTree.DEFAULT_LAZY] * (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): rs = [] l = start + self._offset r = stop + self._offset while l < r: if l & 1 == 0: yield l if r & 1 == 0: rs.append(r - 1) l = l // 2 r = (r - 1) // 2 yield from rs[::-1] def _propagate(self, start, stop): lazy = self._lazy values = self._values indexes = [] for i in self._iter_segmen_indexes(start, stop): if i == 0: return while i != 0: i = (i - 1) // 2 indexes.append(i) for i in sorted(set(indexes)): l = lazy[i] if l == SegmentTree.DEFAULT_LAZY: continue lazy[i * 2 + 1] += l values[i * 2 + 1] += l lazy[i * 2 + 2] += l values[i * 2 + 2] += l lazy[i] = SegmentTree.DEFAULT_LAZY def apply(self, start, stop, value): op = SegmentTree.op values = self._values lazy = self._lazy self._propagate(start, stop) for i in self._iter_segmen_indexes(start, stop): lazy[i] += value values[i] += value while i >= 1: i = (i - 1) // 2 values[i] = op(values[i * 2 + 1], values[i * 2 + 2]) def query(self, start, stop): op = SegmentTree.op values = self._values self._propagate(start, stop) result = SegmentTree.DEFAULT_VALUE for i in self._iter_segmen_indexes(start, stop): result = op(result, values[i]) return result readline = stdin.readline 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')