結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
68,228 KB
testcase_01 AC 63 ms
68,228 KB
testcase_02 AC 61 ms
68,228 KB
testcase_03 AC 68 ms
68,228 KB
testcase_04 AC 62 ms
68,228 KB
testcase_05 AC 62 ms
68,228 KB
testcase_06 AC 618 ms
94,468 KB
testcase_07 AC 641 ms
93,396 KB
testcase_08 AC 696 ms
101,284 KB
testcase_09 AC 598 ms
90,612 KB
testcase_10 AC 645 ms
101,164 KB
testcase_11 AC 602 ms
94,108 KB
testcase_12 AC 637 ms
104,720 KB
testcase_13 AC 590 ms
94,600 KB
testcase_14 AC 668 ms
101,788 KB
testcase_15 AC 624 ms
94,724 KB
testcase_16 AC 609 ms
104,528 KB
testcase_17 AC 623 ms
100,436 KB
testcase_18 AC 633 ms
94,580 KB
testcase_19 AC 699 ms
104,920 KB
testcase_20 AC 662 ms
101,496 KB
testcase_21 AC 594 ms
94,624 KB
testcase_22 AC 711 ms
105,176 KB
testcase_23 AC 571 ms
90,468 KB
testcase_24 AC 673 ms
91,032 KB
testcase_25 AC 640 ms
105,104 KB
testcase_26 AC 579 ms
109,376 KB
testcase_27 AC 560 ms
109,384 KB
testcase_28 AC 576 ms
109,384 KB
testcase_29 AC 593 ms
109,388 KB
testcase_30 AC 729 ms
104,896 KB
testcase_31 AC 724 ms
105,000 KB
testcase_32 AC 667 ms
96,640 KB
testcase_33 AC 703 ms
99,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Callable, Generic, TypeVar, List
T = TypeVar("T")
class SegmentTree(Generic[T]):
    def __init__(self, op:Callable[[T, T], T], e:Callable[[], T], N:int):
        self._length = 1
        while self._length < N:
            self._length <<= 1
        
        self._tree: List[T] = [e()] * (self._length * 2)
        self._op = op
        self._e = e

    def __getitem__(self, key):
        return self._tree[key + self._length]

    def set(self, key:int, val:T):
        key += self._length
        self._tree[key] = val
        key >>= 1
        while key:
            self.update(key)
            key >>= 1

    def update(self, key:int):
        self._tree[key] = self._op(self._tree[2*key], self._tree[2*key + 1])
    
    def prod(self, l:int, r:int) -> T:
        l += self._length
        r += self._length

        sml, smr = self._e(), self._e()

        while l < r:
            if l & 1 : sml = self._op(sml, self._tree[l]); l += 1
            if r & 1 : r -= 1; smr = self._op(self._tree[r], smr)
            l >>= 1; r >>= 1
        
        return self._op(sml, smr)


N, M, K = map(int, input().split())
S = list(map(int, input().split()))
for i in range(K + 1):
    S[i] -= 1
dist = [[1<<60 for _ in range(N)] for _ in range(N)]

for i in range(N):dist[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])


def op(x:int, y:int):
    return x + y

def e():
    return 0

seg = SegmentTree(op, e, K + 1)
for i in range(K):
    seg.set(i, dist[S[i]][S[i+1]])

Q = int(input())

while Q:
    Q -= 1
    t, x, y = map(int, input().split())
    y -= 1

    if t == 1:
        S[x] = y
        if x > 0 : seg.set(x-1, dist[y][S[x-1]])
        if x < K : seg.set(x, dist[y][S[x+1]])
    else:
        print(seg.prod(x, y+1))
0