結果
問題 | No.2640 traO Stamps |
ユーザー | hato336 |
提出日時 | 2024-02-19 21:50:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 475 ms / 2,000 ms |
コード長 | 3,815 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,724 KB |
実行使用メモリ | 124,156 KB |
最終ジャッジ日時 | 2024-09-29 01:49:16 |
合計ジャッジ時間 | 15,563 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
89,300 KB |
testcase_01 | AC | 138 ms
89,132 KB |
testcase_02 | AC | 136 ms
89,240 KB |
testcase_03 | AC | 139 ms
89,024 KB |
testcase_04 | AC | 137 ms
89,104 KB |
testcase_05 | AC | 136 ms
89,120 KB |
testcase_06 | AC | 409 ms
109,592 KB |
testcase_07 | AC | 384 ms
109,308 KB |
testcase_08 | AC | 472 ms
115,636 KB |
testcase_09 | AC | 369 ms
105,056 KB |
testcase_10 | AC | 425 ms
115,436 KB |
testcase_11 | AC | 388 ms
106,680 KB |
testcase_12 | AC | 426 ms
118,640 KB |
testcase_13 | AC | 385 ms
107,720 KB |
testcase_14 | AC | 431 ms
115,352 KB |
testcase_15 | AC | 403 ms
110,132 KB |
testcase_16 | AC | 387 ms
114,988 KB |
testcase_17 | AC | 408 ms
115,320 KB |
testcase_18 | AC | 397 ms
107,772 KB |
testcase_19 | AC | 475 ms
118,684 KB |
testcase_20 | AC | 417 ms
115,452 KB |
testcase_21 | AC | 386 ms
110,244 KB |
testcase_22 | AC | 429 ms
118,420 KB |
testcase_23 | AC | 389 ms
104,912 KB |
testcase_24 | AC | 420 ms
105,096 KB |
testcase_25 | AC | 419 ms
118,872 KB |
testcase_26 | AC | 371 ms
123,984 KB |
testcase_27 | AC | 360 ms
123,852 KB |
testcase_28 | AC | 369 ms
123,848 KB |
testcase_29 | AC | 374 ms
124,156 KB |
testcase_30 | AC | 437 ms
118,596 KB |
testcase_31 | AC | 431 ms
118,516 KB |
testcase_32 | AC | 420 ms
112,860 KB |
testcase_33 | AC | 421 ms
115,240 KB |
ソースコード
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 if i != j else 0 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))