結果

問題 No.2640 traO Stamps
ユーザー zer0-starzer0-star
提出日時 2024-02-12 03:33:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,277 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 28,912 KB
最終ジャッジ日時 2024-02-12 03:33:14
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
17,044 KB
testcase_01 AC 29 ms
10,240 KB
testcase_02 AC 28 ms
10,240 KB
testcase_03 RE -
testcase_04 AC 28 ms
10,240 KB
testcase_05 WA -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

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

dist = [[10**18] * N for _ in range(N)]

for i in range(N):
    dist[i][i] = 0

for _ in range(M):
    u, v, w = map(int, input().split())
    dist[u - 1][v - 1] = w
    dist[v - 1][u - 1] = w

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])

P = int(math.sqrt(K))

baby = [0] * K
giant = [0] * ((K + P - 1) // P)

for i in range(K):
    baby[i] = dist[S[i] - 1][S[i + 1] - 1]
    giant[i // P] += baby[i]

Q = int(input())

for _ in range(Q):
    T, X, Y = map(int, input().split())

    if T == 1:
        S[X] = Y

        if X > 0:
            giant[(X - 1) // P] -= baby[X - 1]
            baby[X - 1] = dist[S[X - 1] - 1][S[X] - 1]
            giant[(X - 1) // P] += baby[X - 1]

        if X < K:
            giant[X // P] -= baby[X]
            baby[X] = dist[S[X] - 1][S[X + 1] - 1]
            giant[X // P] += baby[X]
    else:
        ans = 0
        x = (X + P - 1) // P
        y = Y // P

        for i in range(x, y):
            ans += giant[i]
        for i in range(X, x * P):
            ans += baby[i]
        for i in range(y * P, Y):
            ans += baby[i]

        print(ans)
0