結果

問題 No.2640 traO Stamps
ユーザー umezoumezo
提出日時 2024-02-21 07:13:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 2,598 ms
コンパイル使用メモリ 206,392 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-21 07:13:09
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MAX=210;
const ll INF=1e18;

ll dis[MAX][MAX];
int n,m,k;

void floyd(){
  rep(k,n){
    rep(i,n){
      if(dis[i][k]==INF) continue;
      rep(j,n){
        if(dis[k][j]==INF) continue;
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
      }
    }
  }
}

template<typename T>
struct BIT{
private:
  vector<T> A;
  const int n;
  
public:
  BIT(int _n) : A(_n+1,0), n(_n){}
  
  T sum(int i){
    i++;
    T s=0;
    while(i>0){
      s+=A[i];
      i-=i&-i;
    }
    return s;
  }
  
  T sum(int i,int j){
    return sum(j)-sum(i-1);
  }
  
  void add(int i,T x){
    i++;
    while(i<=n){
      A[i]+=x;
      i+=i&-i;
    }
  }

  void update(int i,T x){
    T tmp=sum(i,i);
    if(tmp!=x) add(i,x-tmp);
  }
};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  cin>>n>>m>>k;
  vector<int> S(k+1);
  rep(i,k+1){
    cin>>S[i];
    S[i]--;
  }
  
  rep(i,n){
    rep(j,n){
      if(i==j) dis[i][j]=0;
      else dis[i][j]=INF;
    }
  }
  
  rep(i,m){
    int s,t;
    ll u;
    cin>>s>>t>>u;
    s--,t--;
    dis[s][t]=u;
    dis[t][s]=u;
  }
  
  floyd();
  BIT<ll> bit(k);
  rep(i,k) bit.add(i,dis[S[i]][S[i+1]]);
  
  int q;
  cin>>q;
  while(q--){
    int t,x,y;
    cin>>t>>x>>y;
    y--;
    if(t==1){
      if(x) bit.update(x-1,dis[S[x-1]][y]);
      bit.update(x,dis[y][S[x+1]]);
      S[x]=y;
    }
    else cout<<bit.sum(x,y)<<'\n';
  }
  
  return 0;
}
0