結果

問題 No.2640 traO Stamps
ユーザー rlangevinrlangevin
提出日時 2024-02-20 12:06:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 2,435 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 108,028 KB
最終ジャッジ日時 2024-02-20 12:06:27
合計ジャッジ時間 12,798 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 340 ms
94,832 KB
testcase_07 AC 305 ms
94,612 KB
testcase_08 AC 444 ms
100,480 KB
testcase_09 AC 284 ms
90,088 KB
testcase_10 AC 350 ms
100,588 KB
testcase_11 AC 325 ms
94,488 KB
testcase_12 AC 337 ms
103,688 KB
testcase_13 AC 309 ms
94,568 KB
testcase_14 AC 371 ms
100,624 KB
testcase_15 AC 354 ms
94,648 KB
testcase_16 AC 305 ms
100,512 KB
testcase_17 AC 334 ms
100,392 KB
testcase_18 AC 330 ms
94,612 KB
testcase_19 AC 390 ms
103,732 KB
testcase_20 AC 336 ms
100,584 KB
testcase_21 AC 327 ms
94,652 KB
testcase_22 AC 354 ms
103,700 KB
testcase_23 AC 291 ms
90,188 KB
testcase_24 AC 358 ms
92,380 KB
testcase_25 AC 350 ms
103,848 KB
testcase_26 AC 314 ms
108,028 KB
testcase_27 AC 313 ms
108,028 KB
testcase_28 AC 331 ms
108,028 KB
testcase_29 AC 320 ms
108,028 KB
testcase_30 AC 372 ms
103,880 KB
testcase_31 AC 399 ms
103,932 KB
testcase_32 AC 363 ms
97,600 KB
testcase_33 AC 368 ms
100,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self,
                 n,
                 identity_e,
                 combine_f,
                 ):
        self._n = n
        self._size = 1
        while self._size < self._n:
            self._size <<= 1
        self._identity_e = identity_e
        self._combine_f = combine_f
        self._node = [self._identity_e] * (2 * self._size)
        
    def build(self, array):
        assert len(array) == self._n
        for index, value in enumerate(array, start=self._size):
            self._node[index] = value
        for index in range(self._size - 1, 0, -1):
            self._node[index] = self._combine_f(
                self._node[index << 1 | 0],
                self._node[index << 1 | 1]
            )
            
    def update(self, index, value):
        i = self._size + index
        self._node[i] = value
        while i > 1:
            i >>= 1
            self._node[i] = self._combine_f(
                self._node[i << 1 | 0],
                self._node[i << 1 | 1]
            )
            
    def fold(self, L, R):
        L += self._size
        R += self._size
        value_L = self._identity_e
        value_R = self._identity_e
        while L < R:
            if L & 1:
                value_L = self._combine_f(value_L, self._node[L])
                L += 1
            if R & 1:
                R -= 1
                value_R = self._combine_f(self._node[R], value_R)
            L >>= 1
            R >>= 1
        
        return self._combine_f(value_L, value_R)
    
    
N, M, K = map(int, input().split())
S = list(map(int, input().split()))
inf = 10 ** 18
G = [[inf] * N for i in range(N)]
for i in range(K + 1):
    S[i] -= 1
for i in range(N):
    G[i][i] = 0
    
for i in range(M):
    A, B, C = map(int, input().split())
    A, B = A - 1, B - 1
    G[A][B] = C
    G[B][A] = C
    
from operator import add
T = SegmentTree(K + 5, 0, add)
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])
            
for i in range(K):
    T.update(i, G[S[i]][S[i + 1]])
    
Q = int(input())
for _ in range(Q):
    t, x, y = map(int, input().split())
    if t == 1:
        S[x] = y - 1
        if x:
            T.update(x - 1, G[S[x - 1]][S[x]])
        if x != K:
            T.update(x, G[S[x]][S[x + 1]])
    else:
        print(T.fold(x, y))
0