結果

問題 No.1234 典型RMQ
ユーザー titiatitia
提出日時 2020-09-18 22:27:16
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 2,985 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 95,492 KB
最終ジャッジ日時 2023-08-08 18:47:18
合計ジャッジ時間 10,577 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,884 KB
testcase_01 AC 72 ms
71,168 KB
testcase_02 AC 72 ms
71,072 KB
testcase_03 AC 72 ms
71,328 KB
testcase_04 AC 73 ms
71,212 KB
testcase_05 AC 72 ms
70,944 KB
testcase_06 AC 369 ms
90,332 KB
testcase_07 AC 315 ms
80,012 KB
testcase_08 AC 375 ms
94,924 KB
testcase_09 AC 353 ms
85,172 KB
testcase_10 AC 365 ms
93,336 KB
testcase_11 AC 359 ms
90,216 KB
testcase_12 AC 338 ms
84,016 KB
testcase_13 AC 319 ms
80,056 KB
testcase_14 AC 344 ms
84,132 KB
testcase_15 AC 340 ms
83,240 KB
testcase_16 AC 374 ms
92,828 KB
testcase_17 AC 351 ms
83,876 KB
testcase_18 AC 296 ms
79,512 KB
testcase_19 AC 374 ms
94,632 KB
testcase_20 AC 285 ms
94,212 KB
testcase_21 AC 375 ms
90,408 KB
testcase_22 AC 345 ms
95,040 KB
testcase_23 AC 340 ms
95,492 KB
testcase_24 AC 342 ms
95,040 KB
testcase_25 AC 345 ms
95,412 KB
testcase_26 AC 345 ms
95,160 KB
testcase_27 AC 72 ms
71,332 KB
testcase_28 AC 71 ms
71,332 KB
testcase_29 AC 71 ms
71,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

# 非再帰遅延伝搬セグ木(範囲加算, 範囲最小値出力)
# 高々N点を更新

seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[1<<60]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

for i in range(N): # Aを対応する箇所へupdate
    SEG[i+seg_el]=A[i]

for i in range(seg_el-1,0,-1): # 親の部分もupdate
    SEG[i]=min(SEG[i*2],SEG[i*2+1])


LAZY=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def indexes(L,R): # 遅延伝搬すべきノードのリストを下から上の順に返す. (つまり, updateやgetvaluesで見るノードより上にあるノードたち)
    INDLIST=[]

    R-=1
    
    L>>=1
    R>>=1

    while L!=R:
        if L>R:
            INDLIST.append(L)
            L>>=1
        else:
            INDLIST.append(R)
            R>>=1

    while L!=0:
        INDLIST.append(L)
        L>>=1

    return INDLIST
        

def adds(l,r,x): # 区間[l,r)を +x 更新
        
    L=l+seg_el
    R=r+seg_el

    L//=(L & (-L))
    R//=(R & (-R))

    UPIND=indexes(L,R)
    
    for ind in UPIND[::-1]: # 遅延伝搬. 上から更新していく. (ただし, 今回はうまくやるとこの部分を省ける. addはクエリの順番によらないので. addではなく, updateの場合必要)
        if LAZY[ind]!=0:
            plus_lazy=LAZY[ind]
            
            SEG[ind<<1]+=plus_lazy
            SEG[1+(ind<<1)]+=plus_lazy
            
            LAZY[ind<<1]+=plus_lazy
            LAZY[1+(ind<<1)]+=plus_lazy
            
            LAZY[ind]=0
    
    while L!=R:
        if L > R:
            SEG[L]+=x
            LAZY[L]+=x
            L+=1
            L//=(L & (-L))

        else:
            R-=1
            SEG[R]+=x
            LAZY[R]+=x
            R//=(R & (-R))

    for ind in UPIND:
        SEG[ind]=min(SEG[ind<<1],SEG[1+(ind<<1)]) # 最初の遅延伝搬を省いた場合, ここを変える
        
def getvalues(l,r): # 区間[l,r)に関するminを調べる

    L=l+seg_el
    R=r+seg_el

    L//=(L & (-L))
    R//=(R & (-R))

    UPIND=indexes(L,R)
    
    for ind in UPIND[::-1]: # 遅延伝搬
        if LAZY[ind]!=0:
            plus_lazy=LAZY[ind]
            
            SEG[ind<<1]+=plus_lazy
            SEG[1+(ind<<1)]+=plus_lazy
            
            LAZY[ind<<1]+=plus_lazy
            LAZY[1+(ind<<1)]+=plus_lazy
            
            LAZY[ind]=0
            
    ANS=1<<60

    while L!=R:
        if L > R:
            ANS=min(ANS , SEG[L])
            L+=1
            L//=(L & (-L))

        else:
            R-=1
            ANS=min(ANS , SEG[R])
            R//=(R & (-R))

    return ANS

Q=int(input())
for queries in range(Q):
    k,l,r,c=map(int,input().split())
    if k==1:
        adds(l-1,r,c)
    else:
        print(getvalues(l-1,r))
    
0