結果

問題 No.2640 traO Stamps
ユーザー ゼットゼット
提出日時 2024-02-19 22:07:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,452 KB
最終ジャッジ日時 2024-02-19 22:08:19
合計ジャッジ時間 16,479 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,460 KB
testcase_01 AC 31 ms
53,460 KB
testcase_02 AC 32 ms
53,460 KB
testcase_03 AC 33 ms
53,460 KB
testcase_04 AC 31 ms
53,460 KB
testcase_05 AC 31 ms
53,460 KB
testcase_06 AC 508 ms
95,676 KB
testcase_07 AC 444 ms
95,660 KB
testcase_08 AC 524 ms
100,816 KB
testcase_09 AC 437 ms
91,156 KB
testcase_10 AC 491 ms
100,796 KB
testcase_11 AC 461 ms
93,164 KB
testcase_12 AC 518 ms
103,912 KB
testcase_13 AC 436 ms
93,268 KB
testcase_14 AC 533 ms
100,840 KB
testcase_15 AC 487 ms
93,368 KB
testcase_16 AC 472 ms
100,692 KB
testcase_17 AC 473 ms
100,708 KB
testcase_18 AC 470 ms
93,316 KB
testcase_19 AC 548 ms
104,104 KB
testcase_20 AC 472 ms
100,944 KB
testcase_21 AC 473 ms
93,368 KB
testcase_22 AC 499 ms
104,068 KB
testcase_23 AC 439 ms
91,156 KB
testcase_24 AC 503 ms
91,304 KB
testcase_25 AC 513 ms
104,252 KB
testcase_26 AC 450 ms
104,452 KB
testcase_27 AC 433 ms
104,452 KB
testcase_28 AC 427 ms
104,452 KB
testcase_29 AC 482 ms
104,452 KB
testcase_30 AC 527 ms
104,136 KB
testcase_31 AC 556 ms
104,328 KB
testcase_32 AC 508 ms
98,260 KB
testcase_33 AC 514 ms
100,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segtree:
  def __init__(self,n):
    self.size=1
    while self.size<n:
      self.size*=2
    self.dat=[0]*(self.size*2)
  def update(self,x,a):
    x+=self.size
    self.dat[x]=a
    while x>1:
      x//=2
      self.dat[x]=(self.dat[2*x]+self.dat[2*x+1])
  def querry(self,u,v):
    u+=self.size
    v+=self.size
    score=0
    while u<v:
      if u&1:
        score+=self.dat[u]
        u+=1
      if v&1:
        v-=1
        score+=self.dat[v]
      u//=2
      v//=2
    return score
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(K+1):
  A[i]-=1
dist=[[10**15]*N for i in range(N)]
for i in range(N):
  dist[i][i]=0
for i in range(M):
  a,b,c=map(int,input().split())
  dist[a-1][b-1]=c
  dist[b-1][a-1]=c
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])
Z=segtree(K)
for i in range(K):
  pos=A[i]
  pos2=A[i+1]
  Z.update(i,dist[pos][pos2])
Q=int(input())
for i in range(Q):
  t,x,y=map(int,input().split())
  if t==1:
    A[x]=y-1
    if x>0:
      Z.update(x-1,dist[A[x]][A[x-1]])
    if x<K:
      Z.update(x,dist[A[x]][A[x+1]])
  else:
    result=Z.querry(x,y)
    print(result)
0