結果

問題 No.2640 traO Stamps
ユーザー rikein12rikein12
提出日時 2024-02-19 23:37:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 692 ms / 2,000 ms
コード長 2,167 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 104,448 KB
最終ジャッジ日時 2024-02-19 23:37:24
合計ジャッジ時間 18,898 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,460 KB
testcase_01 AC 33 ms
53,460 KB
testcase_02 AC 32 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 34 ms
53,460 KB
testcase_06 AC 543 ms
95,288 KB
testcase_07 AC 539 ms
95,148 KB
testcase_08 AC 603 ms
100,428 KB
testcase_09 AC 429 ms
90,900 KB
testcase_10 AC 629 ms
100,408 KB
testcase_11 AC 586 ms
93,040 KB
testcase_12 AC 556 ms
103,524 KB
testcase_13 AC 625 ms
92,888 KB
testcase_14 AC 670 ms
100,452 KB
testcase_15 AC 664 ms
92,860 KB
testcase_16 AC 572 ms
100,304 KB
testcase_17 AC 600 ms
100,320 KB
testcase_18 AC 560 ms
92,808 KB
testcase_19 AC 604 ms
103,588 KB
testcase_20 AC 477 ms
100,428 KB
testcase_21 AC 582 ms
92,860 KB
testcase_22 AC 692 ms
103,680 KB
testcase_23 AC 486 ms
91,028 KB
testcase_24 AC 616 ms
91,052 KB
testcase_25 AC 533 ms
103,852 KB
testcase_26 AC 518 ms
104,448 KB
testcase_27 AC 522 ms
104,448 KB
testcase_28 AC 544 ms
104,448 KB
testcase_29 AC 573 ms
104,448 KB
testcase_30 AC 514 ms
103,620 KB
testcase_31 AC 515 ms
103,684 KB
testcase_32 AC 485 ms
97,360 KB
testcase_33 AC 494 ms
100,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
            
    def __init__(self, L):
        self.N = len(L)
        self.bit = [0]*self.N
        for i,l in enumerate(L):
            self.add(i,l)
        self.N0 = 1
        while self.N0*2 <= self.N:
            self.N0 *= 2

    def add(self, a, w):
        x = a + 1
        for i in range(1000):
            self.bit[x-1] += w
            x += x & -x
            if x > self.N:
                break

    def sum(self, a):
        x = a+1
        ret = 0
        for i in range(1000):
            ret += self.bit[x-1]
            x -= x & -x
            if x <= 0:
                break        
        return ret

    #you can use this function when the BIT has only non-negative values.
    def lower_bound(self, w):
        if w<=0:
            return 0
        x = 0
        k = self.N0
        while k>0:
            if x+k<=self.N:
                if self.bit[x+k-1]<w:
                    w-=self.bit[x+k-1]
                    x+=k
            k//=2
        return x+1
    
N,M,K = list(map(int,input().split()))
S = list(map(int,input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
    u,v,d = list(map(int,input().split()))
    u -= 1
    v -= 1
    e_list[u].append((v,d))
    e_list[v].append((u,d))

INF = float("inf")
D = [[INF]*N for i in range(N)]
for i in range(N):
    D[i][i] = 0
for i in range(N):
    for j,d in e_list[i]:
        D[i][j]=d

for k in range(N):
    for i in range(N):
        for j in range(N):
            if D[i][j]>D[i][k]+D[k][j]:
                D[i][j] = D[i][k]+D[k][j]
S = [s-1 for s in S]
base = [D[S[i]][S[i+1]] for i in range(K)]
bit = BIT(base)

Q = int(input())
for i in range(Q):
    #print(base)
    T,X,Y = list(map(int,input().split()))
    if T==1:
        S[X] = Y - 1
        if X>0:
            bit.add(X-1, D[S[X-1]][S[X]] - base[X-1])
            base[X-1] = D[S[X-1]][S[X]]
        if X<=K-1:
            bit.add(X, D[S[X]][S[X+1]] - base[X])
            base[X] = D[S[X]][S[X+1]]
    else:
        if X>0:
            print(bit.sum(Y-1) - bit.sum(X-1))
        else:
            if Y > 0:
                print(bit.sum(Y-1))
            else:
                print(0)
0