結果

問題 No.2640 traO Stamps
ユーザー Nzt3Nzt3
提出日時 2024-02-19 22:00:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 208,940 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 22:00:24
合計ジャッジ時間 6,390 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 48 ms
6,676 KB
testcase_07 AC 49 ms
6,676 KB
testcase_08 AC 55 ms
6,676 KB
testcase_09 AC 44 ms
6,676 KB
testcase_10 AC 53 ms
6,676 KB
testcase_11 AC 43 ms
6,676 KB
testcase_12 AC 59 ms
6,676 KB
testcase_13 AC 43 ms
6,676 KB
testcase_14 AC 54 ms
6,676 KB
testcase_15 AC 47 ms
6,676 KB
testcase_16 AC 53 ms
6,676 KB
testcase_17 AC 50 ms
6,676 KB
testcase_18 AC 48 ms
6,676 KB
testcase_19 AC 53 ms
6,676 KB
testcase_20 AC 54 ms
6,676 KB
testcase_21 AC 45 ms
6,676 KB
testcase_22 AC 53 ms
6,676 KB
testcase_23 AC 44 ms
6,676 KB
testcase_24 AC 48 ms
6,676 KB
testcase_25 AC 54 ms
6,676 KB
testcase_26 AC 47 ms
6,676 KB
testcase_27 AC 49 ms
6,676 KB
testcase_28 AC 50 ms
6,676 KB
testcase_29 AC 52 ms
6,676 KB
testcase_30 AC 60 ms
6,676 KB
testcase_31 AC 60 ms
6,676 KB
testcase_32 AC 57 ms
6,676 KB
testcase_33 AC 59 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
namespace Lib {
struct BIT {
  vector<ll> a;
  int sz;
  BIT(int n) : sz(n), a(n + 1) {}
  void add(int p, ll v) {
    for (p += 1; p <= sz; p += p & -p) a[p] += v;
  }
  ll sum(int l, int r) {
    ll ret = 0;
    for (; r > 0; r -= r & -r) ret += a[r];
    for (; l > 0; l -= l & -l) ret -= a[l];
    return ret;
  }
};
}  // namespace Lib

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M,K;
  cin>>N>>M>>K;
  vector S(K+1,0);
  for(int &i:S)cin>>i,--i;
  vector dist(N,vector(N,(ll)1e18));
  for(int i=0;i<M;i++){
    int A,B,C;
    cin>>A>>B>>C;
    --A,--B;
    dist[A][B]=C;
    dist[B][A]=C;
  }
  for(int i=0;i<N;i++)dist[i][i]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
      }
    }
  }
  // for(int i=0;i<N;i++){
  //   for(int j=0;j<N;j++)cout<<dist[i][j]<<' ';cout<<'\n';
  // }

  Lib::BIT seg(K);
  for(int i=0;i<K;i++){
    seg.add(i,dist[S[i]][S[i+1]]);
  }
  int Q;
  cin>>Q;
  while(Q--){
    int T,X,Y;
    cin>>T>>X>>Y;
    if(T==1){
      --Y;
      if(X>0)seg.add(X-1,-dist[S[X-1]][S[X]]);
      if(X<K)seg.add(X,-dist[S[X]][S[X+1]]);
      S[X]=Y;
      if(X>0)seg.add(X-1,dist[S[X-1]][S[X]]);
      if(X<K)seg.add(X,dist[S[X]][S[X+1]]);
    }else{
      cout<<seg.sum(X,Y)<<'\n';
    }
  }
}
0