結果
問題 | No.2640 traO Stamps |
ユーザー | PNJ |
提出日時 | 2024-02-19 21:52:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 848 ms / 2,000 ms |
コード長 | 3,534 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 82,528 KB |
実行使用メモリ | 104,972 KB |
最終ジャッジ日時 | 2024-09-29 01:51:27 |
合計ジャッジ時間 | 22,515 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,080 KB |
testcase_01 | AC | 39 ms
53,940 KB |
testcase_02 | AC | 40 ms
53,988 KB |
testcase_03 | AC | 37 ms
54,028 KB |
testcase_04 | AC | 37 ms
54,420 KB |
testcase_05 | AC | 37 ms
53,892 KB |
testcase_06 | AC | 668 ms
95,132 KB |
testcase_07 | AC | 688 ms
95,216 KB |
testcase_08 | AC | 751 ms
101,016 KB |
testcase_09 | AC | 566 ms
90,804 KB |
testcase_10 | AC | 765 ms
100,972 KB |
testcase_11 | AC | 734 ms
93,000 KB |
testcase_12 | AC | 679 ms
104,064 KB |
testcase_13 | AC | 758 ms
93,060 KB |
testcase_14 | AC | 815 ms
100,856 KB |
testcase_15 | AC | 808 ms
92,756 KB |
testcase_16 | AC | 724 ms
101,168 KB |
testcase_17 | AC | 760 ms
100,924 KB |
testcase_18 | AC | 693 ms
93,368 KB |
testcase_19 | AC | 728 ms
104,192 KB |
testcase_20 | AC | 596 ms
101,196 KB |
testcase_21 | AC | 734 ms
93,264 KB |
testcase_22 | AC | 848 ms
103,920 KB |
testcase_23 | AC | 640 ms
91,264 KB |
testcase_24 | AC | 785 ms
90,956 KB |
testcase_25 | AC | 646 ms
104,216 KB |
testcase_26 | AC | 647 ms
104,972 KB |
testcase_27 | AC | 647 ms
104,964 KB |
testcase_28 | AC | 660 ms
104,948 KB |
testcase_29 | AC | 700 ms
104,852 KB |
testcase_30 | AC | 654 ms
104,044 KB |
testcase_31 | AC | 655 ms
104,284 KB |
testcase_32 | AC | 626 ms
97,848 KB |
testcase_33 | AC | 631 ms
100,864 KB |
ソースコード
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)]) def add(x,y): return x + y def Warshall_Floid(n,edge): INF = float("INF") dist = [ [INF for i in range(n)] for j in range(n)] for i in range(n): dist[i][i] = 0 for u in range(n): for v,r in edge[u]: dist[u][v] = r 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]) return dist def Map(): return list(map(int,input().split())) N,M,K = Map() S = Map() for i in range(K+1): S[i] -= 1 G = [[] for i in range(N)] for i in range(M): A,B,C = Map() A -= 1 B -= 1 G[A].append((B,C)) G[B].append((A,C)) dist = Warshall_Floid(N,G) seg = segtree([0 for i in range(K+1)],add,0) for i in range(1,K+1): d = dist[S[i-1]][S[i]] seg.set(i,d) Q = int(input()) for _ in range(Q): t,x,y = Map() if t == 1: y -= 1 S[x] = y if x > 0: seg.set(x,dist[y][S[x-1]]) if x < K: seg.set(x+1,dist[y][S[x+1]]) else: print(seg.prod(x+1,y+1))