結果

問題 No.2640 traO Stamps
ユーザー katonyonkokatonyonko
提出日時 2024-02-19 22:31:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 647 ms / 2,000 ms
コード長 2,656 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,572 KB
最終ジャッジ日時 2024-02-19 22:31:36
合計ジャッジ時間 16,406 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,736 KB
testcase_01 AC 39 ms
55,736 KB
testcase_02 AC 39 ms
55,736 KB
testcase_03 AC 42 ms
55,736 KB
testcase_04 AC 40 ms
55,736 KB
testcase_05 AC 40 ms
55,736 KB
testcase_06 AC 456 ms
96,100 KB
testcase_07 AC 400 ms
95,828 KB
testcase_08 AC 420 ms
101,744 KB
testcase_09 AC 301 ms
91,188 KB
testcase_10 AC 505 ms
101,872 KB
testcase_11 AC 413 ms
93,456 KB
testcase_12 AC 379 ms
104,408 KB
testcase_13 AC 475 ms
93,564 KB
testcase_14 AC 647 ms
101,896 KB
testcase_15 AC 584 ms
93,664 KB
testcase_16 AC 433 ms
101,660 KB
testcase_17 AC 574 ms
101,812 KB
testcase_18 AC 436 ms
93,484 KB
testcase_19 AC 596 ms
104,340 KB
testcase_20 AC 425 ms
101,292 KB
testcase_21 AC 440 ms
93,664 KB
testcase_22 AC 525 ms
104,360 KB
testcase_23 AC 396 ms
91,316 KB
testcase_24 AC 558 ms
91,472 KB
testcase_25 AC 458 ms
104,532 KB
testcase_26 AC 364 ms
104,572 KB
testcase_27 AC 371 ms
104,572 KB
testcase_28 AC 363 ms
104,572 KB
testcase_29 AC 365 ms
104,572 KB
testcase_30 AC 527 ms
104,500 KB
testcase_31 AC 505 ms
104,508 KB
testcase_32 AC 493 ms
99,068 KB
testcase_33 AC 496 ms
101,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import io
import sys
from collections import defaultdict, deque, Counter
from itertools import permutations, combinations, accumulate
from heapq import heappush, heappop
from bisect import bisect_right, bisect_left
from math import gcd
import math

_INPUT = """\
6
4 5 3
1 2 4 2
1 2 1
3 4 2
2 4 5
1 3 2
2 3 7
10
2 0 3
1 1 3
2 0 2
2 1 1
1 0 2
2 0 3
"""

INF=10**20
def WF(cost):
  for k in range(len(cost)):
      for i in range(len(cost)):
          for j in range(len(cost)):
              if cost[i][k]!=INF and cost[k][j]!=INF:
                  cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
  return cost

class BIT:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n
    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p
    #合計にはrを含まない
    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)
    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s
    #pの位置をxという値にセット
    def set(self, p, x):
        self.add(p, -self.sum(p, p+1) + x)

def input():
  return sys.stdin.readline()[:-1]

def solve(test):
  N,M,K=map(int, input().split())
  S=list(map(lambda x:int(x)-1, input().split()))
  cost=[[INF]*N for _ in range(N)]
  for i in range(N): cost[i][i]=0
  for i in range(M):
    a,b,c=map(int, input().split())
    cost[a-1][b-1]=c
    cost[b-1][a-1]=c
  cost=WF(cost)
  bit=BIT(K)
  for i in range(K): bit.add(i,cost[S[i]][S[i+1]])
  Q=int(input())
  for _ in range(Q):
    q=list(map(int, input().split()))
    if q[0]==1:
      a,b=q[1],q[2]-1
      S[a]=b
      if a<K: bit.set(a,cost[S[a]][S[a+1]])
      if a>0: bit.set(a-1,cost[S[a-1]][S[a]])
    else:
      l,r=q[1],q[2]
      print(bit.sum(l,r))

def random_input():
  from random import randint,shuffle
  N=randint(1,10)
  M=randint(1,N)
  A=list(range(1,M+1))+[randint(1,M) for _ in range(N-M)]
  shuffle(A)
  return (" ".join(map(str, [N,M]))+"\n"+" ".join(map(str, A))+"\n")*3

def simple_solve():
  return []

def main(test):
  if test==0:
    solve(0)
  elif test==1:
    sys.stdin = io.StringIO(_INPUT)
    case_no=int(input())
    for _ in range(case_no):
      solve(0)
  else:
    for i in range(1000):
      sys.stdin = io.StringIO(random_input())
      x=solve(1)
      y=simple_solve()
      if x!=y:
        print(i,x,y)
        print(*[line for line in sys.stdin],sep='')
        break

#0:提出用、1:与えられたテスト用、2:ストレステスト用
main(0)
0