結果

問題 No.2640 traO Stamps
ユーザー zer0-starzer0-star
提出日時 2024-02-12 19:05:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 796 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,708 KB
最終ジャッジ日時 2024-02-12 19:06:13
合計ジャッジ時間 21,346 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,588 KB
testcase_01 AC 35 ms
53,588 KB
testcase_02 AC 34 ms
53,588 KB
testcase_03 AC 38 ms
53,588 KB
testcase_04 AC 35 ms
53,588 KB
testcase_05 AC 34 ms
53,588 KB
testcase_06 AC 590 ms
95,932 KB
testcase_07 AC 574 ms
95,788 KB
testcase_08 AC 663 ms
100,944 KB
testcase_09 AC 520 ms
91,296 KB
testcase_10 AC 596 ms
100,924 KB
testcase_11 AC 496 ms
93,436 KB
testcase_12 AC 624 ms
103,784 KB
testcase_13 AC 549 ms
93,540 KB
testcase_14 AC 629 ms
100,712 KB
testcase_15 AC 544 ms
93,628 KB
testcase_16 AC 573 ms
101,076 KB
testcase_17 AC 573 ms
100,964 KB
testcase_18 AC 588 ms
93,460 KB
testcase_19 AC 604 ms
103,976 KB
testcase_20 AC 630 ms
100,816 KB
testcase_21 AC 553 ms
93,508 KB
testcase_22 AC 616 ms
103,940 KB
testcase_23 AC 526 ms
91,296 KB
testcase_24 AC 551 ms
91,576 KB
testcase_25 AC 561 ms
104,124 KB
testcase_26 AC 730 ms
104,708 KB
testcase_27 AC 733 ms
104,708 KB
testcase_28 AC 673 ms
104,708 KB
testcase_29 AC 796 ms
104,708 KB
testcase_30 AC 643 ms
104,008 KB
testcase_31 AC 668 ms
104,072 KB
testcase_32 AC 601 ms
98,260 KB
testcase_33 AC 622 ms
101,176 KB
権限があれば一括ダウンロードができます

ソースコード

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

        if x >= y:
            for i in range(X, Y):
                ans += baby[i]
            print(ans)
            continue

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

        print(ans)

0