結果
問題 | No.2640 traO Stamps |
ユーザー | chineristAC |
提出日時 | 2024-02-19 23:11:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 717 ms / 2,000 ms |
コード長 | 2,269 bytes |
コンパイル時間 | 414 ms |
コンパイル使用メモリ | 81,852 KB |
実行使用メモリ | 137,852 KB |
最終ジャッジ日時 | 2024-09-29 02:52:30 |
合計ジャッジ時間 | 19,699 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
import sys from itertools import permutations from heapq import heappop,heappush from collections import deque import random import bisect input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.size = n for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = x while k > 1: k >>= 1 self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1]) def query(self, l, r): if r==self.size: r = self.num res = self.ide_ele l += self.num r += self.num right = [] while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: right.append(self.tree[r-1]) l >>= 1 r >>= 1 for e in right[::-1]: res = self.segfunc(res,e) return res INF = 10**17 N,M,K = mi() A = li() edge = [[INF]*N for i in range(N)] for _ in range(M): a,b,c = mi() edge[a-1][b-1] = min(edge[a-1][b-1],c) edge[b-1][a-1] = min(edge[b-1][a-1],c) for i in range(N): edge[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): if edge[i][j] > edge[i][k] + edge[k][j]: edge[i][j] = edge[i][k] + edge[k][j] e = (-1,-1) def merge(x,y): if x == e: return y if y == e: return x c = x[0] + y[0] + edge[x[2]][y[1]] return (c,x[1],y[2]) seg = SegmentTree([(0,A[i]-1,A[i]-1) for i in range(K+1)],merge,e) res = [] for _ in range(int(input())): t,x,y = mi() if t == 1: seg.update(x,(0,y-1,y-1)) continue l,r = x,y #print("l,r",l,r) ans = seg.query(l,r+1)[0] res.append(ans) print(*res,sep="\n")