結果

問題 No.2640 traO Stamps
ユーザー twooimp2twooimp2
提出日時 2024-02-20 01:13:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 6,306 ms
コンパイル使用メモリ 305,304 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-02-20 01:14:06
合計ジャッジ時間 12,874 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 125 ms
6,676 KB
testcase_07 AC 134 ms
6,676 KB
testcase_08 AC 139 ms
6,676 KB
testcase_09 AC 129 ms
6,676 KB
testcase_10 AC 126 ms
6,676 KB
testcase_11 AC 116 ms
6,676 KB
testcase_12 AC 130 ms
6,676 KB
testcase_13 AC 112 ms
6,676 KB
testcase_14 AC 155 ms
6,676 KB
testcase_15 AC 124 ms
6,676 KB
testcase_16 AC 115 ms
6,676 KB
testcase_17 AC 122 ms
6,676 KB
testcase_18 AC 133 ms
6,676 KB
testcase_19 AC 133 ms
6,676 KB
testcase_20 AC 131 ms
6,676 KB
testcase_21 AC 127 ms
6,676 KB
testcase_22 AC 138 ms
6,676 KB
testcase_23 AC 124 ms
6,676 KB
testcase_24 AC 129 ms
6,676 KB
testcase_25 AC 128 ms
6,676 KB
testcase_26 AC 142 ms
6,784 KB
testcase_27 AC 152 ms
6,784 KB
testcase_28 AC 135 ms
6,784 KB
testcase_29 AC 169 ms
6,784 KB
testcase_30 AC 149 ms
6,676 KB
testcase_31 AC 144 ms
6,676 KB
testcase_32 AC 136 ms
6,676 KB
testcase_33 AC 139 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

int main(){
  IO();
  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll> s(k+1);
  for(ll i=0;i<=k;i++){
    cin>>s[i];
    s[i]--;
  }
  vector<vector<ll>> dist(n,vector<ll>(n,1e18));
  for(ll i=0;i<n;i++){
    dist[i][i]=0;
  }
  for(ll i=0;i<m;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    dist[a][b]=c;
    dist[b][a]=c;
  }
  for(ll l=0;l<n;l++){
    for(ll i=0;i<n;i++){
      for(ll j=0;j<n;j++){
        dist[i][j]=min(dist[i][j],dist[i][l]+dist[l][j]);
      }
    }
  }
  fenwick_tree<ll> bit(k);
  for(ll i=0;i<k;i++){
    bit.add(i,dist[s[i]][s[i+1]]);
  }
  ll q;
  cin>>q;
  while(q--){
    ll t,x,y;
    cin>>t>>x>>y;
    if(t==1){
      y--;
      if(x-1>=0){
        bit.add(x-1,-dist[s[x-1]][s[x]]);
      }
      if(x+1<=k){
        bit.add(x,-dist[s[x]][s[x+1]]);
      }
      s[x]=y;
      if(x-1>=0){
        bit.add(x-1,dist[s[x-1]][s[x]]);
      }
      if(x+1<=k){
        bit.add(x,dist[s[x]][s[x+1]]);
      }
    }else{
      cout<<bit.sum(x,y)<<endl;
    }
  }
}
0