結果

問題 No.2640 traO Stamps
ユーザー tassei903tassei903
提出日時 2024-02-19 22:02:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 2,977 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 106,020 KB
最終ジャッジ日時 2024-02-19 22:02:43
合計ジャッジ時間 15,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,588 KB
testcase_01 AC 34 ms
53,588 KB
testcase_02 AC 33 ms
53,588 KB
testcase_03 AC 33 ms
53,588 KB
testcase_04 AC 33 ms
53,588 KB
testcase_05 AC 34 ms
53,588 KB
testcase_06 AC 400 ms
96,676 KB
testcase_07 AC 423 ms
96,496 KB
testcase_08 AC 474 ms
102,840 KB
testcase_09 AC 398 ms
91,632 KB
testcase_10 AC 431 ms
102,800 KB
testcase_11 AC 372 ms
93,848 KB
testcase_12 AC 449 ms
106,020 KB
testcase_13 AC 441 ms
93,988 KB
testcase_14 AC 466 ms
102,736 KB
testcase_15 AC 399 ms
94,208 KB
testcase_16 AC 439 ms
102,784 KB
testcase_17 AC 452 ms
102,784 KB
testcase_18 AC 394 ms
94,068 KB
testcase_19 AC 480 ms
105,960 KB
testcase_20 AC 456 ms
102,784 KB
testcase_21 AC 415 ms
94,080 KB
testcase_22 AC 482 ms
105,856 KB
testcase_23 AC 394 ms
91,776 KB
testcase_24 AC 425 ms
91,776 KB
testcase_25 AC 475 ms
105,904 KB
testcase_26 AC 374 ms
105,600 KB
testcase_27 AC 393 ms
105,600 KB
testcase_28 AC 385 ms
105,600 KB
testcase_29 AC 391 ms
105,600 KB
testcase_30 AC 543 ms
105,984 KB
testcase_31 AC 542 ms
105,984 KB
testcase_32 AC 489 ms
99,328 KB
testcase_33 AC 476 ms
102,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
#######################################################################
inf = 10**18
class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : min(x,y), default=inf):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f
 
    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
    def updatef(self, i, x):
        i += self.size
        self.dat[i] = self.f(self.dat[i],x)
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
 
    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1
 
            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
 
    def query2(self):
        s = 1
        #print(self.size)
        while s<self.size:
            #print(s)
            if self.dat[s*2]>self.dat[s*2+1]:
                s = s*2
            else:
                s = s*2+1
        return s-self.size
    
from heapq import *
INF = 10**18
def dijkstra(g, s, n):
    dist = [INF]*n
    hq = [(0, s)]
    dist[s] = 0
    while hq:
        d, v = heappop(hq)
        if dist[v]!=d:
            continue
        for to, c in g[v]:
            if dist[v] + c < dist[to]:
                dist[to] = dist[v] + c
                heappush(hq, (dist[to], to))
    return dist
n,m,k = na()
s = [x-1 for x in na()]
inf = 10**18
g = [[] for _ in range(n)]
for _ in range(m):
    a,b,c = na()
    a -= 1
    b -= 1
    g[a].append((b,c))
    g[b].append( (a,c))

dist = [dijkstra(g, i, n) for i in range(n)]

def f(x, y):
    return x + y
st = SegmentTree(k, lambda x,y : x+y, 0)
for i in range(k):
    #print(i, dist[s[i]][s[i+1]])
    st.update(i, dist[s[i]][s[i+1]])

q = ni()

for _ in range(q):
    t,x,y = na()
    if t==1:
        y -= 1
        if x>0:
            st.update(x-1, dist[s[x-1]][y])
            #print("update", x-1, dist[s[x-1]][y])
        if x<k:
            st.update(x, dist[y][s[x+1]])
            #print("update", x, dist[y][s[x+1]])
        s[x] = y
    else:
        print(st.query(x,y))
0