結果

問題 No.2640 traO Stamps
ユーザー 👑 rin204rin204
提出日時 2024-02-19 21:41:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 3,680 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 104,436 KB
最終ジャッジ日時 2024-02-19 21:42:14
合計ジャッジ時間 16,809 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
53,460 KB
testcase_01 AC 30 ms
53,460 KB
testcase_02 AC 30 ms
53,460 KB
testcase_03 AC 32 ms
53,460 KB
testcase_04 AC 31 ms
53,460 KB
testcase_05 AC 31 ms
53,460 KB
testcase_06 AC 482 ms
95,532 KB
testcase_07 AC 447 ms
95,388 KB
testcase_08 AC 547 ms
100,544 KB
testcase_09 AC 479 ms
91,152 KB
testcase_10 AC 490 ms
100,652 KB
testcase_11 AC 500 ms
93,152 KB
testcase_12 AC 515 ms
103,768 KB
testcase_13 AC 471 ms
93,380 KB
testcase_14 AC 506 ms
100,696 KB
testcase_15 AC 462 ms
93,352 KB
testcase_16 AC 451 ms
100,420 KB
testcase_17 AC 509 ms
100,436 KB
testcase_18 AC 469 ms
93,172 KB
testcase_19 AC 555 ms
103,832 KB
testcase_20 AC 503 ms
100,672 KB
testcase_21 AC 458 ms
93,224 KB
testcase_22 AC 567 ms
103,796 KB
testcase_23 AC 451 ms
91,152 KB
testcase_24 AC 499 ms
91,300 KB
testcase_25 AC 511 ms
103,980 KB
testcase_26 AC 418 ms
104,436 KB
testcase_27 AC 435 ms
104,436 KB
testcase_28 AC 435 ms
104,436 KB
testcase_29 AC 471 ms
104,436 KB
testcase_30 AC 516 ms
103,992 KB
testcase_31 AC 512 ms
104,056 KB
testcase_32 AC 561 ms
98,116 KB
testcase_33 AC 567 ms
100,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTreeBase_:
    def ope(self, l, r):
        raise NotImplementedError

    def e(self):
        raise NotImplementedError

    def __init__(self, n, init=None):
        self.n = n
        self.n0 = 1 << (n - 1).bit_length()
        self.data = [self.e()] * (2 * self.n0)
        if init is not None:
            for i in range(n):
                self.data[self.n0 + i] = init[i]
            for i in range(self.n0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])

    def build(self):
        for i in range(self.n0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])

    def set(self, i, x):
        i += self.n0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])

    def get(self, i):
        return self.data[i + self.n0]

    def __getitem__(self, i):
        return self.data[i + self.n0]

    def __setitem__(self, i, x):
        self.set(i, x)

    def prod(self, l, r):
        assert 0 <= l <= r <= self.n0
        l += self.n0
        r += self.n0
        lles = self.e()
        rres = self.e()
        while l < r:
            if l & 1:
                lles = self.ope(lles, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lles, rres)

    def max_right(self, l, f):
        if l == self.n:
            return self.n
        l += self.n0
        sm = self.e()
        while 1:
            while l % 2 == 0:
                l >>= 1
            if not f(self.ope(sm, self.data[l])):
                while l < self.n0:
                    l <<= 1
                    if f(self.ope(sm, self.data[l])):
                        sm = self.ope(sm, self.data[l])
                        l += 1
                return l - self.n0
            sm = self.ope(sm, self.data[l])
            l += 1
            if l & -l == l:
                break
        return self.n

    def min_left(self, r, f):
        if r == 0:
            return 0
        r += self.n0
        sm = self.e()
        while 1:
            r -= 1
            while r > 1 and r % 2:
                r >>= 1
            if not f(self.ope(self.data[r], sm)):
                while r < self.n0:
                    r = 2 * r + 1
                    if f(self.ope(self.data[r], sm)):
                        sm = self.ope(self.data[r], sm)
                        r -= 1
                return r + 1 - self.n0
            sm = self.ope(self.data[r], sm)
            if r & -r == r:
                break
        return 0


class RangeSum(SegmentTreeBase_):
    def ope(self, l, r):
        return l + r

    def e(self):
        return 0


n, m, k = map(int, input().split())
S = list(map(int, input().split()))
dist = [[1 << 60] * 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())
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c

for t in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][t] + dist[t][j])

for i in range(k + 1):
    S[i] -= 1

C = [0] * k
for i in range(k):
    d = dist[S[i]][S[i + 1]]
    C[i] = d

seg = RangeSum(k, C)

Q = int(input())
for _ in range(Q):
    t, x, y = map(int, input().split())
    if t == 1:
        y -= 1
        S[x] = y
        if x != 0:
            seg.set(x - 1, dist[S[x - 1]][S[x]])
        if x != k:
            seg.set(x, dist[S[x]][S[x + 1]])
    else:
        print(seg.prod(x, y))
0