結果

問題 No.2640 traO Stamps
ユーザー hirayuu_ychirayuu_yc
提出日時 2024-02-19 21:36:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,930 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 109,876 KB
最終ジャッジ日時 2024-02-19 21:36:20
合計ジャッジ時間 10,312 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,460 KB
testcase_01 AC 32 ms
53,460 KB
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 32 ms
53,460 KB
testcase_04 AC 31 ms
53,460 KB
testcase_05 AC 32 ms
53,460 KB
testcase_06 AC 242 ms
96,828 KB
testcase_07 AC 233 ms
96,684 KB
testcase_08 AC 242 ms
102,808 KB
testcase_09 AC 191 ms
92,680 KB
testcase_10 AC 275 ms
102,748 KB
testcase_11 AC 213 ms
95,048 KB
testcase_12 AC 215 ms
106,048 KB
testcase_13 AC 215 ms
95,328 KB
testcase_14 AC 260 ms
103,204 KB
testcase_15 AC 230 ms
96,496 KB
testcase_16 AC 217 ms
102,788 KB
testcase_17 AC 245 ms
102,772 KB
testcase_18 AC 234 ms
95,288 KB
testcase_19 AC 256 ms
106,208 KB
testcase_20 AC 244 ms
102,872 KB
testcase_21 AC 213 ms
97,680 KB
testcase_22 AC 262 ms
106,260 KB
testcase_23 AC 226 ms
91,948 KB
testcase_24 AC 303 ms
91,968 KB
testcase_25 AC 282 ms
106,264 KB
testcase_26 AC 263 ms
109,876 KB
testcase_27 AC 258 ms
109,876 KB
testcase_28 AC 233 ms
109,876 KB
testcase_29 AC 245 ms
109,872 KB
testcase_30 AC 264 ms
106,080 KB
testcase_31 AC 286 ms
106,176 KB
testcase_32 AC 259 ms
99,412 KB
testcase_33 AC 255 ms
102,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BinaryIndexedTree():
    def __init__(self,default=0):
        self.size=0
        if type(default)==int:
            self.size=default
        else:
            self.size=len(default)
        self.bit=[0 for i in range(self.size+1)]
        self.stan=[0 for i in range(self.size)]
        if type(default)!=int:
            for i,j in enumerate(default):
                self[i]=j
    
    def __setitem__(self,pos,val):
        add=val-self.stan[pos]
        self.stan[pos]=val
        pos+=1
        while pos<=self.size:
            self.bit[pos]+=add
            pos+=pos&(-pos)
    
    def __getitem__(self,pos):
        if type(pos)==int:
            return self.stan[pos]
        else:
            left=pos.start
            if left==None:
                left=0
            right=pos.stop
            if right==None:
                right=self.size
            return self._sum0(right-1)-self._sum0(left-1)
        
    def _sum0(self,right):
        pos=right+1
        ret=0
        while pos>0:
            ret+=self.bit[pos]
            pos-=pos&(-pos)
        return ret

import sys
#sys.setrecursionlimit((1<<19)-1)
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
input=sys.stdin.buffer.readline

INF=1<<60
N,M,K=map(int,input().split())
K+=2
S=list(map(int,input().split()))+[1]
di=[[INF]*N for i in range(N)]
for i in range(N):
    di[i][i]=0
for i in range(M):
    A,B,C=map(int,input().split())
    di[A-1][B-1]=C
    di[B-1][A-1]=C
for i in range(N):
    for j in range(N):
        for k in range(N):
            di[j][k]=min(di[j][k],di[j][i]+di[i][k])
st=[0]*K
S[0]-=1
for i in range(K-1):
    S[i+1]-=1
    st[i+1]=di[S[i]][S[i+1]]
bit=BinaryIndexedTree(st)
Q=int(input())
for i in range(Q):
    T,X,Y=map(int,input().split())
    if T==1:
        Y-=1
        S[X]=Y
        if X!=0:
            bit[X]=di[S[X-1]][Y]
        bit[X+1]=di[Y][S[X+1]]
    else:
        print(bit[X+1:Y+1])
0