結果

問題 No.2640 traO Stamps
ユーザー titiatitia
提出日時 2024-02-24 02:58:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,088 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 103,840 KB
最終ジャッジ日時 2024-02-24 02:58:41
合計ジャッジ時間 12,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,332 KB
testcase_01 AC 35 ms
53,332 KB
testcase_02 AC 37 ms
53,332 KB
testcase_03 AC 36 ms
53,332 KB
testcase_04 WA -
testcase_05 AC 36 ms
53,332 KB
testcase_06 AC 322 ms
95,056 KB
testcase_07 AC 334 ms
94,820 KB
testcase_08 AC 374 ms
100,856 KB
testcase_09 AC 221 ms
90,200 KB
testcase_10 AC 355 ms
100,708 KB
testcase_11 WA -
testcase_12 AC 278 ms
103,808 KB
testcase_13 AC 368 ms
92,592 KB
testcase_14 AC 475 ms
100,616 KB
testcase_15 AC 412 ms
92,672 KB
testcase_16 AC 377 ms
100,504 KB
testcase_17 AC 380 ms
100,512 KB
testcase_18 AC 334 ms
92,508 KB
testcase_19 AC 341 ms
103,724 KB
testcase_20 AC 272 ms
100,704 KB
testcase_21 AC 341 ms
92,548 KB
testcase_22 AC 437 ms
103,820 KB
testcase_23 AC 290 ms
90,400 KB
testcase_24 AC 359 ms
90,532 KB
testcase_25 AC 291 ms
103,840 KB
testcase_26 AC 285 ms
103,728 KB
testcase_27 AC 271 ms
103,728 KB
testcase_28 AC 284 ms
103,728 KB
testcase_29 AC 281 ms
103,728 KB
testcase_30 AC 308 ms
103,744 KB
testcase_31 AC 293 ms
103,796 KB
testcase_32 AC 280 ms
97,716 KB
testcase_33 AC 278 ms
100,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M,K=map(int,input().split())
S=list(map(int,input().split()))

# グラフの最短距離を全て求める(ワーシャル–フロイド法)

Distance=[[float("inf") for i in range(N+1)] for j in range(N+1)]

for i in range(N+1):
    Distance[i][i]=0

for i in range(M):
    i,j,t=map(int,input().split())
    Distance[i][j]=Distance[j][i]=t # 分かっている距離を書き込んでおく.

for k in range(1,N+1): # k個までの町を使ってのDisが知れているときに
    for i in range(1,N+1): # 町iと
        for j in range(i,N+1): # 町jとの最短距離は、
            length=Distance[i][k]+Distance[j][k]
            if Distance[i][j]>length:
                Distance[i][j]=Distance[j][i]=length

def seg_function(x,y): # Segment treeで扱うfunction
    return x+y

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

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

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

def update(n,x,seg_el): # A[n]をxへ更新
    i=n+seg_el
    SEG[i]=x
    i>>=1 # 子ノードへ
    
    while i!=0:
        SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
        i>>=1
        
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
    L=l+seg_el
    R=r+seg_el
    ANS1=0
    ANS2=0

    while L<R:
        if L & 1:
            ANS1=seg_function(ANS1, SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS2=seg_function(SEG[R], ANS2)
        L>>=1
        R>>=1

    return seg_function(ANS1, ANS2)

LANS=[]
Q=int(input())
for tests in range(Q):
    com,x,y=map(int,input().split())

    if com==1:
        S[x]=y

        if x-1>=0:
            update(x-1,Distance[S[x-1]][S[x]],seg_el)

        if x+1<K:
            update(x,Distance[S[x]][S[x+1]],seg_el)
    else:
        LANS.append(getvalues(x,y))

print("\n".join(map(str,LANS)))
0