結果

問題 No.2640 traO Stamps
ユーザー hato336hato336
提出日時 2024-02-19 21:50:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 3,815 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 123,024 KB
最終ジャッジ日時 2024-02-19 21:50:46
合計ジャッジ時間 16,808 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
88,160 KB
testcase_01 AC 146 ms
88,160 KB
testcase_02 AC 145 ms
88,160 KB
testcase_03 AC 147 ms
88,160 KB
testcase_04 AC 143 ms
88,160 KB
testcase_05 AC 144 ms
88,160 KB
testcase_06 AC 452 ms
109,024 KB
testcase_07 AC 406 ms
108,768 KB
testcase_08 AC 485 ms
114,528 KB
testcase_09 AC 417 ms
104,416 KB
testcase_10 AC 434 ms
114,528 KB
testcase_11 AC 427 ms
106,336 KB
testcase_12 AC 430 ms
117,600 KB
testcase_13 AC 397 ms
109,280 KB
testcase_14 AC 482 ms
114,400 KB
testcase_15 AC 418 ms
109,792 KB
testcase_16 AC 399 ms
114,144 KB
testcase_17 AC 445 ms
114,272 KB
testcase_18 AC 405 ms
107,360 KB
testcase_19 AC 472 ms
117,728 KB
testcase_20 AC 424 ms
114,528 KB
testcase_21 AC 398 ms
109,664 KB
testcase_22 AC 471 ms
117,472 KB
testcase_23 AC 397 ms
104,416 KB
testcase_24 AC 430 ms
104,672 KB
testcase_25 AC 436 ms
117,856 KB
testcase_26 AC 384 ms
123,020 KB
testcase_27 AC 389 ms
123,024 KB
testcase_28 AC 384 ms
122,896 KB
testcase_29 AC 392 ms
123,024 KB
testcase_30 AC 486 ms
117,728 KB
testcase_31 AC 459 ms
117,856 KB
testcase_32 AC 449 ms
111,584 KB
testcase_33 AC 460 ms
114,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
class segtree():
    n=1
    size=1
    log=2
    d=[0]
    op=None
    e=10**15
    def __init__(self,V,OP,E):
        self.n=len(V)
        self.op=OP
        self.e=E
        self.log=(self.n-1).bit_length()
        self.size=1<<self.log
        self.d=[E for i in range(2*self.size)]
        for i in range(self.n):
            self.d[self.size+i]=V[i]
        for i in range(self.size-1,0,-1):
            self.update(i)
    def set(self,p,x):
        assert 0<=p and p<self.n
        p+=self.size
        self.d[p]=x
        for i in range(1,self.log+1):
            self.update(p>>i)
    def get(self,p):
        assert 0<=p and p<self.n
        return self.d[p+self.size]
    def prod(self,l,r):
        assert 0<=l and l<=r and r<=self.n
        sml=self.e
        smr=self.e
        l+=self.size
        r+=self.size
        while(l<r):
            if (l&1):
                sml=self.op(sml,self.d[l])
                l+=1
            if (r&1):
                smr=self.op(self.d[r-1],smr)
                r-=1
            l>>=1
            r>>=1
        return self.op(sml,smr)
    def all_prod(self):
        return self.d[1]
    def max_right(self,l,f):
        assert 0<=l and l<=self.n
        assert f(self.e)
        if l==self.n:
            return self.n
        l+=self.size
        sm=self.e
        while(1):
            while(l%2==0):
                l>>=1
            if not(f(self.op(sm,self.d[l]))):
                while(l<self.size):
                    l=2*l
                    if f(self.op(sm,self.d[l])):
                        sm=self.op(sm,self.d[l])
                        l+=1
                return l-self.size
            sm=self.op(sm,self.d[l])
            l+=1
            if (l&-l)==l:
                break
        return self.n
    def min_left(self,r,f):
        assert 0<=r and r<=self.n
        assert f(self.e)
        if r==0:
            return 0
        r+=self.size
        sm=self.e
        while(1):
            r-=1
            while(r>1 and (r%2)):
                r>>=1
            if not(f(self.op(self.d[r],sm))):
                while(r<self.size):
                    r=(2*r+1)
                    if f(self.op(self.d[r],sm)):
                        sm=self.op(self.d[r],sm)
                        r-=1
                return r+1-self.size
            sm=self.op(self.d[r],sm)
            if (r& -r)==r:
                break
        return 0
    def update(self,k):
        self.d[k]=self.op(self.d[2*k],self.d[2*k+1])
    def __str__(self):
        return str([self.get(i) for i in range(self.n)])
#alist = list(map(int,input().split()))
#alist = []
#s = input()
n,m,k = map(int,input().split())
s = list(map(lambda x:int(x)-1,input().split()))
edge = [[] for i in range(n)]
dist = [[10**18  if i != j else 0 for i in range(n)] for j in range(n)]
for i in range(m):
    u,v,w = map(int,input().split())
    u-=1
    v-=1
    edge[u].append((v,w))
    edge[v].append((u,w))
    dist[u][v] = min(dist[u][v],w)
    dist[v][u] = min(dist[v][u],w)
q = int(input())

for K in range(n):
    for i in range(n):
        for j in range(n):
            if dist[i][j] > dist[i][K] + dist[K][j]:
                dist[i][j] = dist[i][K] + dist[K][j]

cost = [0 for i in range(k)]
for i in range(k):
    cost[i] = dist[s[i]][s[i+1]]
st = segtree(cost,operator.add,0)
for i in range(q):
    t,x,y = map(int,input().split())
    if t == 1:
        s[x] = y-1
        if x != 0:
            st.set(x-1,dist[s[x-1]][s[x]])
        if x != k:
            st.set(x,dist[s[x+1]][s[x]])
    else:
        if x == y:
            print(0)
            continue
        print(st.prod(x,y))
0