結果

問題 No.1234 典型RMQ
ユーザー tamatotamato
提出日時 2020-09-18 21:37:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 635 ms / 2,000 ms
コード長 2,887 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 105,216 KB
最終ジャッジ日時 2024-04-26 11:02:22
合計ジャッジ時間 13,662 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,608 KB
testcase_01 AC 44 ms
52,864 KB
testcase_02 AC 43 ms
52,608 KB
testcase_03 AC 41 ms
52,736 KB
testcase_04 AC 39 ms
52,716 KB
testcase_05 AC 42 ms
52,480 KB
testcase_06 AC 615 ms
99,584 KB
testcase_07 AC 480 ms
85,116 KB
testcase_08 AC 611 ms
104,320 KB
testcase_09 AC 536 ms
92,416 KB
testcase_10 AC 610 ms
102,656 KB
testcase_11 AC 624 ms
99,072 KB
testcase_12 AC 565 ms
91,656 KB
testcase_13 AC 450 ms
84,608 KB
testcase_14 AC 564 ms
91,984 KB
testcase_15 AC 552 ms
90,568 KB
testcase_16 AC 613 ms
102,656 KB
testcase_17 AC 567 ms
92,240 KB
testcase_18 AC 415 ms
81,744 KB
testcase_19 AC 635 ms
104,192 KB
testcase_20 AC 238 ms
101,120 KB
testcase_21 AC 623 ms
98,944 KB
testcase_22 AC 434 ms
105,216 KB
testcase_23 AC 450 ms
104,320 KB
testcase_24 AC 443 ms
104,832 KB
testcase_25 AC 446 ms
105,088 KB
testcase_26 AC 455 ms
104,832 KB
testcase_27 AC 42 ms
52,864 KB
testcase_28 AC 42 ms
52,480 KB
testcase_29 AC 43 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    class LazySegTree:
        # Range add query
        def __init__(self, A, initialize=True, segfunc=min, ident=2000000000):
            self.N = len(A)
            self.LV = (self.N - 1).bit_length()
            self.N0 = 1 << self.LV
            self.segfunc = segfunc
            self.ident = ident
            if 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 >>= 1
                self.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 >> j
                x = self.lazy[i]
                if not x:
                    continue
                self.lazy[i] = 0
                self.lazy[i * 2] += x
                self.lazy[i * 2 + 1] += x
                self.data[i * 2] += x
                self.data[i * 2 + 1] += x

        # open interval [l, r)
        def add(self, l, r, x):
            l += self.N0 - 1
            r += self.N0 - 1
            l_ori = l
            r_ori = r
            while l < r:
                if l & 1:
                    self.data[l] += x
                    self.lazy[l] += x
                    l += 1
                if r & 1:
                    r -= 1
                    self.data[r] += x
                    self.lazy[r] += x
                l >>= 1
                r >>= 1
            self._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 - 1
            r += self.N0 - 1
            self._descend(l // (l & -l))
            self._descend(r // (r & -r) - 1)
            ret = self.ident
            while l < r:
                if l & 1:
                    ret = self.segfunc(ret, self.data[l])
                    l += 1
                if r & 1:
                    ret = self.segfunc(self.data[r - 1], ret)
                    r -= 1
                l >>= 1
                r >>= 1
            return ret

    N = 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()
0