結果
| 問題 |
No.2640 traO Stamps
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 23:37:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 769 ms / 2,000 ms |
| コード長 | 2,167 bytes |
| コンパイル時間 | 185 ms |
| コンパイル使用メモリ | 82,256 KB |
| 実行使用メモリ | 105,100 KB |
| 最終ジャッジ日時 | 2024-09-29 03:14:06 |
| 合計ジャッジ時間 | 20,899 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
ソースコード
class BIT:
def __init__(self, L):
self.N = len(L)
self.bit = [0]*self.N
for i,l in enumerate(L):
self.add(i,l)
self.N0 = 1
while self.N0*2 <= self.N:
self.N0 *= 2
def add(self, a, w):
x = a + 1
for i in range(1000):
self.bit[x-1] += w
x += x & -x
if x > self.N:
break
def sum(self, a):
x = a+1
ret = 0
for i in range(1000):
ret += self.bit[x-1]
x -= x & -x
if x <= 0:
break
return ret
#you can use this function when the BIT has only non-negative values.
def lower_bound(self, w):
if w<=0:
return 0
x = 0
k = self.N0
while k>0:
if x+k<=self.N:
if self.bit[x+k-1]<w:
w-=self.bit[x+k-1]
x+=k
k//=2
return x+1
N,M,K = list(map(int,input().split()))
S = list(map(int,input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
u,v,d = list(map(int,input().split()))
u -= 1
v -= 1
e_list[u].append((v,d))
e_list[v].append((u,d))
INF = float("inf")
D = [[INF]*N for i in range(N)]
for i in range(N):
D[i][i] = 0
for i in range(N):
for j,d in e_list[i]:
D[i][j]=d
for k in range(N):
for i in range(N):
for j in range(N):
if D[i][j]>D[i][k]+D[k][j]:
D[i][j] = D[i][k]+D[k][j]
S = [s-1 for s in S]
base = [D[S[i]][S[i+1]] for i in range(K)]
bit = BIT(base)
Q = int(input())
for i in range(Q):
#print(base)
T,X,Y = list(map(int,input().split()))
if T==1:
S[X] = Y - 1
if X>0:
bit.add(X-1, D[S[X-1]][S[X]] - base[X-1])
base[X-1] = D[S[X-1]][S[X]]
if X<=K-1:
bit.add(X, D[S[X]][S[X+1]] - base[X])
base[X] = D[S[X]][S[X+1]]
else:
if X>0:
print(bit.sum(Y-1) - bit.sum(X-1))
else:
if Y > 0:
print(bit.sum(Y-1))
else:
print(0)