結果
問題 | No.1234 典型RMQ |
ユーザー | marroncastle |
提出日時 | 2020-09-27 10:40:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 438 ms / 2,000 ms |
コード長 | 4,636 bytes |
コンパイル時間 | 372 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 93,184 KB |
最終ジャッジ日時 | 2024-11-09 02:26:50 |
合計ジャッジ時間 | 11,500 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
53,248 KB |
testcase_01 | AC | 44 ms
53,376 KB |
testcase_02 | AC | 45 ms
53,248 KB |
testcase_03 | AC | 45 ms
53,248 KB |
testcase_04 | AC | 45 ms
52,992 KB |
testcase_05 | AC | 45 ms
53,376 KB |
testcase_06 | AC | 408 ms
88,320 KB |
testcase_07 | AC | 373 ms
82,092 KB |
testcase_08 | AC | 424 ms
92,544 KB |
testcase_09 | AC | 404 ms
85,108 KB |
testcase_10 | AC | 438 ms
90,752 KB |
testcase_11 | AC | 416 ms
87,808 KB |
testcase_12 | AC | 397 ms
85,292 KB |
testcase_13 | AC | 394 ms
82,688 KB |
testcase_14 | AC | 389 ms
85,080 KB |
testcase_15 | AC | 394 ms
85,084 KB |
testcase_16 | AC | 436 ms
90,752 KB |
testcase_17 | AC | 407 ms
84,420 KB |
testcase_18 | AC | 360 ms
84,592 KB |
testcase_19 | AC | 425 ms
92,800 KB |
testcase_20 | AC | 333 ms
91,776 KB |
testcase_21 | AC | 416 ms
87,936 KB |
testcase_22 | AC | 413 ms
93,056 KB |
testcase_23 | AC | 401 ms
92,800 KB |
testcase_24 | AC | 403 ms
93,184 KB |
testcase_25 | AC | 409 ms
92,544 KB |
testcase_26 | AC | 404 ms
92,800 KB |
testcase_27 | AC | 44 ms
52,992 KB |
testcase_28 | AC | 44 ms
53,120 KB |
testcase_29 | AC | 46 ms
53,504 KB |
ソースコード
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log self.data = [e] * (2 * self.size) self.lazy = [id] * (self.size) def update(self, k): self.data[k] = self.op(self.data[2 * k], self.data[2 * k + 1]) def all_apply(self, k, f): self.data[k] = self.mapping(f, self.data[k]) if k < self.size: self.lazy[k] = self.composition(f, self.lazy[k]) def push(self, k): # 親の遅延配列の値を子に反映させる self.all_apply(2 * k, self.lazy[k]) self.all_apply(2 * k + 1, self.lazy[k]) self.lazy[k] = self.id def build(self, arr): #assert len(arr) == self.n for i, a in enumerate(arr): self.data[self.size + i] = a for i in range(self.size-1,0,-1): self.update(i) def set(self, p, x): #assert 0 <= p < self.n p += self.size #事前に関係のある遅延配列を全て反映させてしまう for i in range(self.log, 0, -1): self.push(p >> i) self.data[p] = x #値を更新する #関係のある区間の値も更新する for i in range(1, self.log + 1): self.update(p >> i) def get(self, p): #assert 0 <= p < self.n p += self.size #関係のある遅延配列を全て反映させる for i in range(1, self.log + 1): self.push(p >> i) return self.data[p] def prod(self, l, r): #assert 0 <= l <= r <= self.n if l == r: return self.e l += self.size r += self.size for i in range(self.log, 0, -1): if ((l >> i) << i) != l: self.push(l >> i) if ((r >> i) << i) != r: self.push(r >> i) sml = smr = self.e while l < r: if l & 1: sml = self.op(sml, self.data[l]) l += 1 if r & 1: r -= 1 smr = self.op(self.data[r], smr) l >>= 1 r >>= 1 return self.op(sml, smr) def all_prod(self): return self.data[1] def apply(self, p, f): #assert 0 <= p < self.n p += self.size for i in range(self.log, 0, -1): self.push(p >> i) self.data[p] = self.mapping(f, self.data[p]) for i in range(1, self.log + 1): self.update(p >> i) def range_apply(self, l, r, f): #assert 0 <= l <= r <= self.n if l == r: return l += self.size r += self.size for i in range(self.log, 0, -1): if ((l >> i) << i) != l: self.push(l >> i) if ((r >> i) << i) != r: self.push((r - 1) >> i) l2 = l r2 = r while l < r: if l & 1: self.all_apply(l, f) l += 1 if r & 1: r -= 1 self.all_apply(r, f) l >>= 1 r >>= 1 l = l2 r = r2 for i in range(1, self.log + 1): if ((l >> i) << i) != l: self.update(l >> i) if ((r >> i) << i) != r: self.update((r - 1) >> i) def max_right(self, l, g): #assert 0 <= l <= self.n #assert g(self.e) if l == self.n: return self.n l += self.size for i in range(self.log, 0, -1): self.push(l >> i) sm = self.e while True: while l % 2 == 0: l >>= 1 if not g(self.op(sm, self.data[l])): while l < self.size: self.push(l) l = 2 * l if g(self.op(sm, self.data[l])): sm = self.op(sm, self.data[l]) l += 1 return l - self.size sm = self.op(sm, self.data[l]) l += 1 if (l & -l) == l: return self.n def min_left(self, r, g): #assert 0 <= r <= self.n #assert g(self.e) if r == 0: return 0 r += self.size for i in range(self.log, 0, -1): self.push((r - 1) >> i) sm = self.e while True: r -= 1 while r > 1 and r % 2: r >>= 1 if not g(self.op(self.data[r], sm)): while r < self.size: self.push(r) r = 2 * r + 1 if g(self.op(self.data[r], sm)): sm = self.op(self.data[r], sm) r -= 1 return r + 1 - self.size sm = self.op(self.data[r], sm) if (r & -r) == r: return 0 import sys input = sys.stdin.readline INF = 10**18 def mapping(p, x): #pが作用素, xが更新する前の値 return x+p def composition(p, q): return p+q e = INF id = 0 N = int(input()) A = list(map(int, input().split())) Q = int(input()) lst = LazySegmentTree(N, min, e, mapping, composition, id) lst.build(A) ans = [] for _ in range(Q): k,l,r,c = map(int, input().split()) if k==1: lst.range_apply(l-1,r,c) else: ans.append(lst.prod(l-1,r)) print(*ans, sep='\n')