結果

問題 No.1234 典型RMQ
ユーザー hir355hir355
提出日時 2020-09-18 21:59:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 900 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 95,616 KB
最終ジャッジ日時 2024-04-26 11:10:31
合計ジャッジ時間 18,891 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,096 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 42 ms
52,096 KB
testcase_03 AC 40 ms
52,096 KB
testcase_04 AC 38 ms
52,352 KB
testcase_05 AC 37 ms
52,224 KB
testcase_06 AC 835 ms
89,984 KB
testcase_07 AC 806 ms
81,024 KB
testcase_08 AC 850 ms
94,848 KB
testcase_09 AC 797 ms
84,608 KB
testcase_10 AC 843 ms
92,928 KB
testcase_11 AC 849 ms
90,112 KB
testcase_12 AC 878 ms
83,420 KB
testcase_13 AC 731 ms
80,900 KB
testcase_14 AC 812 ms
83,584 KB
testcase_15 AC 772 ms
82,816 KB
testcase_16 AC 843 ms
92,996 KB
testcase_17 AC 771 ms
83,256 KB
testcase_18 AC 678 ms
80,232 KB
testcase_19 AC 900 ms
94,976 KB
testcase_20 AC 506 ms
93,824 KB
testcase_21 AC 811 ms
89,856 KB
testcase_22 AC 728 ms
94,976 KB
testcase_23 AC 753 ms
94,976 KB
testcase_24 AC 709 ms
95,616 KB
testcase_25 AC 711 ms
95,232 KB
testcase_26 AC 814 ms
95,104 KB
testcase_27 AC 41 ms
52,352 KB
testcase_28 AC 41 ms
52,352 KB
testcase_29 AC 41 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
write = sys.stdout.write

N = int(input())
INF = 2**72-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)


def gindex(l, r):
    L = l + N0
    R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1
        R >>= 1
    while L:
        yield L
        L >>= 1


def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v
        lazy[2*i] += v
        data[2*i-1] += v
        data[2*i] += v
        lazy[i-1] = 0


def update(l, r, x):
    L = N0 + l
    R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x
            data[R-1] += x
        if L & 1:
            lazy[L-1] += x
            data[L-1] += x
            L += 1
        L >>= 1
        R >>= 1
    for i in gindex(l, r):
        data[i-1] = min(data[2*i-1], data[2*i]) + lazy[i-1]


def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l
    R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1
        R >>= 1
    return s


a = list(map(int, input().split()))
for i in range(N):
    update(i, i + 1, a[i])
Q = int(input())
for q in range(Q):
    k, s, t, x = map(int, input().split())
    if k == 2:
        print(query(s - 1, t))
    else:
        update(s - 1, t, x)
0