結果
問題 | No.2640 traO Stamps |
ユーザー | hato336 |
提出日時 | 2024-02-19 21:47:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,797 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 124,288 KB |
最終ジャッジ日時 | 2024-09-29 01:43:09 |
合計ジャッジ時間 | 15,058 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
89,088 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 136 ms
88,872 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 | 382 ms
123,776 KB |
testcase_27 | AC | 379 ms
124,288 KB |
testcase_28 | AC | 370 ms
124,032 KB |
testcase_29 | AC | 373 ms
123,904 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
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 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))