結果
問題 | No.1234 典型RMQ |
ユーザー |
![]() |
提出日時 | 2020-09-18 21:37:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 635 ms / 2,000 ms |
コード長 | 2,887 bytes |
コンパイル時間 | 391 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 104,960 KB |
最終ジャッジ日時 | 2024-11-09 01:44:20 |
合計ジャッジ時間 | 13,935 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
mod = 1000000007eps = 10**-9def main():import sysinput = sys.stdin.buffer.readlineclass LazySegTree:# Range add querydef __init__(self, A, initialize=True, segfunc=min, ident=2000000000):self.N = len(A)self.LV = (self.N - 1).bit_length()self.N0 = 1 << self.LVself.segfunc = segfuncself.ident = identif initialize:self.data = [self.ident] * self.N0 + A + [self.ident] * (self.N0 - self.N)for i in range(self.N0 - 1, 0, -1):self.data[i] = segfunc(self.data[i * 2], self.data[i * 2 + 1])else:self.data = [self.ident] * (self.N0 * 2)self.lazy = [0] * (self.N0 * 2)def _ascend(self, i):for _ in range(i.bit_length() - 1):i >>= 1self.data[i] = self.segfunc(self.data[i * 2], self.data[i * 2 + 1]) + self.lazy[i]def _descend(self, idx):lv = idx.bit_length()for j in range(lv - 1, 0, -1):i = idx >> jx = self.lazy[i]if not x:continueself.lazy[i] = 0self.lazy[i * 2] += xself.lazy[i * 2 + 1] += xself.data[i * 2] += xself.data[i * 2 + 1] += x# open interval [l, r)def add(self, l, r, x):l += self.N0 - 1r += self.N0 - 1l_ori = lr_ori = rwhile l < r:if l & 1:self.data[l] += xself.lazy[l] += xl += 1if r & 1:r -= 1self.data[r] += xself.lazy[r] += xl >>= 1r >>= 1self._ascend(l_ori // (l_ori & -l_ori))self._ascend(r_ori // (r_ori & -r_ori) - 1)# open interval [l, r)def query(self, l, r):l += self.N0 - 1r += self.N0 - 1self._descend(l // (l & -l))self._descend(r // (r & -r) - 1)ret = self.identwhile l < r:if l & 1:ret = self.segfunc(ret, self.data[l])l += 1if r & 1:ret = self.segfunc(self.data[r - 1], ret)r -= 1l >>= 1r >>= 1return retN = int(input())A = list(map(int, input().split()))ST = LazySegTree(A, ident=float("inf"))for _ in range(int(input())):k, l, r, c = map(int, input().split())if k == 1:ST.add(l, r+1, c)else:print(ST.query(l, r+1))if __name__ == '__main__':main()