結果

問題 No.2640 traO Stamps
ユーザー SSRSSSRS
提出日時 2024-02-19 21:29:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,693 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 208,812 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 21:30:07
合計ジャッジ時間 9,789 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 177 ms
6,676 KB
testcase_07 AC 222 ms
6,676 KB
testcase_08 AC 206 ms
6,676 KB
testcase_09 AC 181 ms
6,676 KB
testcase_10 AC 189 ms
6,676 KB
testcase_11 AC 169 ms
6,676 KB
testcase_12 AC 200 ms
6,676 KB
testcase_13 AC 164 ms
6,676 KB
testcase_14 AC 200 ms
6,676 KB
testcase_15 AC 181 ms
6,676 KB
testcase_16 AC 197 ms
6,676 KB
testcase_17 AC 182 ms
6,676 KB
testcase_18 AC 190 ms
6,676 KB
testcase_19 AC 216 ms
6,676 KB
testcase_20 AC 199 ms
6,676 KB
testcase_21 AC 180 ms
6,676 KB
testcase_22 AC 200 ms
6,676 KB
testcase_23 AC 183 ms
6,676 KB
testcase_24 AC 189 ms
6,676 KB
testcase_25 AC 190 ms
6,676 KB
testcase_26 AC 194 ms
6,676 KB
testcase_27 AC 198 ms
6,676 KB
testcase_28 AC 190 ms
6,676 KB
testcase_29 AC 219 ms
6,676 KB
testcase_30 AC 219 ms
6,676 KB
testcase_31 AC 220 ms
6,676 KB
testcase_32 AC 207 ms
6,676 KB
testcase_33 AC 242 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;
struct binary_indexed_tree{
  int N;
  vector<long long> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  void add(int i, long long x){
    i++;
    while (i <= N){
      BIT[i] += x;
      i += i & -i;
    }
  }
  long long sum(int i){
    long long ans = 0;
    while (i > 0){
      ans += BIT[i];
      i -= i & -i;
    }
    return ans;
  }
  long long sum(int L, int R){
    return sum(R) - sum(L);
  }
};
int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> S(K + 1);
  for (int i = 0; i <= K; i++){
    cin >> S[i];
    S[i]--;
  }
  vector<vector<long long>> E(N, vector<long long>(N, INF));
  for (int i = 0; i < N; i++){
    E[i][i] = 0;
  }
  for (int i = 0; i < M; i++){
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    E[A][B] = C;
    E[B][A] = C;
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      for (int k = 0; k < N; k++){
        E[j][k] = min(E[j][k], E[j][i] + E[i][k]);
      }
    }
  }
  binary_indexed_tree BIT(K);
  for (int i = 0; i < K; i++){
    BIT.add(i, E[S[i]][S[i + 1]]);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int T;
    cin >> T;
    if (T == 1){
      int X, Y;
      cin >> X >> Y;
      Y--;
      if (X > 0){
        BIT.add(X - 1, -E[S[X - 1]][S[X]]);
      }
      if (X < K){
        BIT.add(X, -E[S[X]][S[X + 1]]);
      }
      S[X] = Y;
      if (X > 0){
        BIT.add(X - 1, E[S[X - 1]][S[X]]);
      }
      if (X < K){
        BIT.add(X, E[S[X]][S[X + 1]]);
      }
    }
    if (T == 2){
      int X, Y;
      cin >> X >> Y;
      cout << BIT.sum(X, Y) << endl;
    }
  }
}
0