結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
6,676 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 74 ms
6,676 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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=1e9+7;

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