結果
問題 | No.2640 traO Stamps |
ユーザー | nikoro256 |
提出日時 | 2024-02-19 22:03:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 410 ms / 2,000 ms |
コード長 | 2,549 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 103,956 KB |
最終ジャッジ日時 | 2024-02-19 22:03:23 |
合計ジャッジ時間 | 12,568 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge16 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,460 KB |
testcase_01 | AC | 36 ms
53,460 KB |
testcase_02 | AC | 35 ms
53,460 KB |
testcase_03 | AC | 37 ms
53,460 KB |
testcase_04 | AC | 35 ms
53,460 KB |
testcase_05 | AC | 37 ms
53,460 KB |
testcase_06 | AC | 340 ms
94,836 KB |
testcase_07 | AC | 291 ms
94,860 KB |
testcase_08 | AC | 410 ms
100,460 KB |
testcase_09 | AC | 272 ms
90,328 KB |
testcase_10 | AC | 340 ms
100,568 KB |
testcase_11 | AC | 289 ms
92,424 KB |
testcase_12 | AC | 339 ms
103,668 KB |
testcase_13 | AC | 293 ms
92,632 KB |
testcase_14 | AC | 356 ms
100,604 KB |
testcase_15 | AC | 367 ms
92,712 KB |
testcase_16 | AC | 299 ms
100,636 KB |
testcase_17 | AC | 323 ms
100,380 KB |
testcase_18 | AC | 292 ms
92,676 KB |
testcase_19 | AC | 400 ms
103,712 KB |
testcase_20 | AC | 322 ms
100,692 KB |
testcase_21 | AC | 288 ms
92,588 KB |
testcase_22 | AC | 360 ms
103,808 KB |
testcase_23 | AC | 280 ms
90,300 KB |
testcase_24 | AC | 327 ms
90,444 KB |
testcase_25 | AC | 337 ms
103,956 KB |
testcase_26 | AC | 305 ms
103,856 KB |
testcase_27 | AC | 305 ms
103,856 KB |
testcase_28 | AC | 309 ms
103,856 KB |
testcase_29 | AC | 313 ms
103,856 KB |
testcase_30 | AC | 363 ms
103,860 KB |
testcase_31 | AC | 386 ms
103,912 KB |
testcase_32 | AC | 344 ms
97,596 KB |
testcase_33 | AC | 349 ms
100,476 KB |
ソースコード
#####segfunc##### def Sum(x, y): return x+y ################# class SegTree: #init(init_val, ide_ele): 配列init_valで初期化 O(N) #update(k, x): k番目の値をxに更新 O(logN) #query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN) def __init__(self, init_val, segfunc, ide_ele): #init_val: 配列の初期値 #segfunc: 区間にしたい操作 #ide_ele: 単位元 #n: 要素数 #num: n以上の最小の2のべき乗 #tree: セグメント木(1-index) n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num # 配列の値を葉にセット for i in range(n): self.tree[self.num + i] = init_val[i] # 構築していく for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): #k番目の値をxに更新 #k: index(0-index) #x: update value k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): #[l, r)のsegfuncしたものを得る #l: index(0-index) #r: index(0-index) res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res import sys input=sys.stdin.readline N,M,K=map(int,input().split()) S=list(map(int,input().split())) dist=[[10**12]*N for _ in range(N)] for _ in range(M): a,b,c=map(int,input().split()) a-=1 b-=1 dist[a][b]=c dist[b][a]=c for i in range(N): dist[i][i]=0 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]) st=SegTree([0]*K,Sum,0) for i in range(K): st.update(i,dist[S[i]-1][S[i+1]-1]) Q=int(input()) ans=[] for _ in range(Q): t,x,y=map(int,input().split()) if t==1: S[x]=y if x!=0: st.update(x-1,dist[S[x-1]-1][S[x]-1]) if x!=K: st.update(x,dist[S[x]-1][S[x+1]-1]) else: ans.append(st.query(x,y)) print(*ans,sep='\n')