結果
問題 | No.2640 traO Stamps |
ユーザー | titia |
提出日時 | 2024-02-24 02:59:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 452 ms / 2,000 ms |
コード長 | 2,089 bytes |
コンパイル時間 | 822 ms |
コンパイル使用メモリ | 81,572 KB |
実行使用メモリ | 103,948 KB |
最終ジャッジ日時 | 2024-02-24 02:59:41 |
合計ジャッジ時間 | 12,523 ms |
ジャッジサーバーID (参考情報) |
judge16 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,460 KB |
testcase_01 | AC | 39 ms
53,460 KB |
testcase_02 | AC | 36 ms
53,460 KB |
testcase_03 | AC | 35 ms
53,460 KB |
testcase_04 | AC | 35 ms
53,460 KB |
testcase_05 | AC | 35 ms
53,460 KB |
testcase_06 | AC | 314 ms
95,056 KB |
testcase_07 | AC | 303 ms
94,820 KB |
testcase_08 | AC | 406 ms
100,856 KB |
testcase_09 | AC | 219 ms
90,200 KB |
testcase_10 | AC | 347 ms
100,836 KB |
testcase_11 | AC | 366 ms
92,388 KB |
testcase_12 | AC | 307 ms
103,808 KB |
testcase_13 | AC | 367 ms
92,592 KB |
testcase_14 | AC | 452 ms
100,744 KB |
testcase_15 | AC | 423 ms
92,800 KB |
testcase_16 | AC | 374 ms
100,504 KB |
testcase_17 | AC | 377 ms
100,512 KB |
testcase_18 | AC | 332 ms
92,508 KB |
testcase_19 | AC | 340 ms
103,852 KB |
testcase_20 | AC | 247 ms
100,832 KB |
testcase_21 | AC | 378 ms
92,548 KB |
testcase_22 | AC | 436 ms
103,948 KB |
testcase_23 | AC | 264 ms
90,400 KB |
testcase_24 | AC | 380 ms
90,532 KB |
testcase_25 | AC | 289 ms
103,840 KB |
testcase_26 | AC | 286 ms
103,728 KB |
testcase_27 | AC | 279 ms
103,728 KB |
testcase_28 | AC | 289 ms
103,728 KB |
testcase_29 | AC | 281 ms
103,728 KB |
testcase_30 | AC | 275 ms
103,744 KB |
testcase_31 | AC | 291 ms
103,796 KB |
testcase_32 | AC | 271 ms
97,716 KB |
testcase_33 | AC | 279 ms
100,600 KB |
ソースコード
import sys input = sys.stdin.readline N,M,K=map(int,input().split()) S=list(map(int,input().split())) # グラフの最短距離を全て求める(ワーシャル–フロイド法) Distance=[[float("inf") for i in range(N+1)] for j in range(N+1)] for i in range(N+1): Distance[i][i]=0 for i in range(M): i,j,t=map(int,input().split()) Distance[i][j]=Distance[j][i]=t # 分かっている距離を書き込んでおく. for k in range(1,N+1): # k個までの町を使ってのDisが知れているときに for i in range(1,N+1): # 町iと for j in range(i,N+1): # 町jとの最短距離は、 length=Distance[i][k]+Distance[j][k] if Distance[i][j]>length: Distance[i][j]=Distance[j][i]=length def seg_function(x,y): # Segment treeで扱うfunction return x+y seg_el=1<<(K.bit_length()) # Segment treeの台の要素数 SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 for i in range(K): # Aを対応する箇所へupdate SEG[i+seg_el]=Distance[S[i]][S[i+1]] for i in range(seg_el-1,0,-1): # 親の部分もupdate SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) def update(n,x,seg_el): # A[n]をxへ更新 i=n+seg_el SEG[i]=x i>>=1 # 子ノードへ while i!=0: SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) i>>=1 def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる L=l+seg_el R=r+seg_el ANS1=0 ANS2=0 while L<R: if L & 1: ANS1=seg_function(ANS1, SEG[L]) L+=1 if R & 1: R-=1 ANS2=seg_function(SEG[R], ANS2) L>>=1 R>>=1 return seg_function(ANS1, ANS2) LANS=[] Q=int(input()) for tests in range(Q): com,x,y=map(int,input().split()) if com==1: S[x]=y if x-1>=0: update(x-1,Distance[S[x-1]][S[x]],seg_el) if x+1<=K: update(x,Distance[S[x]][S[x+1]],seg_el) else: LANS.append(getvalues(x,y)) print("\n".join(map(str,LANS)))