結果

問題 No.2640 traO Stamps
ユーザー rikein12rikein12
提出日時 2024-02-19 23:27:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,132 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,576 KB
最終ジャッジ日時 2024-02-19 23:28:03
合計ジャッジ時間 18,666 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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