結果
問題 | 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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
56,724 KB |
testcase_01 | AC | 45 ms
57,356 KB |
testcase_02 | AC | 44 ms
56,208 KB |
testcase_03 | AC | 46 ms
57,844 KB |
testcase_04 | AC | 43 ms
57,788 KB |
testcase_05 | AC | 44 ms
57,344 KB |
testcase_06 | AC | 575 ms
124,284 KB |
testcase_07 | AC | 558 ms
127,888 KB |
testcase_08 | AC | 672 ms
134,724 KB |
testcase_09 | AC | 496 ms
117,996 KB |
testcase_10 | AC | 619 ms
131,680 KB |
testcase_11 | AC | 510 ms
118,392 KB |
testcase_12 | AC | 617 ms
134,416 KB |
testcase_13 | AC | 549 ms
119,200 KB |
testcase_14 | AC | 651 ms
133,544 KB |
testcase_15 | AC | 559 ms
122,608 KB |
testcase_16 | AC | 559 ms
130,060 KB |
testcase_17 | AC | 592 ms
131,412 KB |
testcase_18 | AC | 566 ms
123,612 KB |
testcase_19 | AC | 633 ms
133,580 KB |
testcase_20 | AC | 600 ms
133,892 KB |
testcase_21 | AC | 550 ms
122,480 KB |
testcase_22 | AC | 633 ms
136,108 KB |
testcase_23 | AC | 536 ms
119,304 KB |
testcase_24 | AC | 583 ms
119,544 KB |
testcase_25 | AC | 629 ms
135,372 KB |
testcase_26 | AC | 417 ms
126,300 KB |
testcase_27 | AC | 410 ms
126,632 KB |
testcase_28 | AC | 413 ms
126,308 KB |
testcase_29 | AC | 424 ms
127,448 KB |
testcase_30 | AC | 717 ms
137,852 KB |
testcase_31 | AC | 699 ms
137,448 KB |
testcase_32 | AC | 665 ms
130,660 KB |
testcase_33 | AC | 632 ms
131,540 KB |
ソースコード
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")