結果

問題 No.2640 traO Stamps
ユーザー nono00nono00
提出日時 2024-02-19 22:52:44
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,234 bytes
コンパイル時間 3,508 ms
コンパイル使用メモリ 254,084 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 22:52:53
合計ジャッジ時間 7,249 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#include <vector>

namespace nono {

template <class T>
class FenwickTree {
  public:
    FenwickTree(int size = 0): size_(size), data_(size_ + 1) {}

    void add(int i, const T& v) {
        for (++i; i <= size_; i += i & -i) {
            data_[i] += v;
        }
    }

    T sum(int i) const {
        T result{};
        for (; i > 0; i -= i & -i) {
            result += data_[i];
        }
        return result;
    }

    T sum(int l, int r) const {
        return sum(r) - sum(l);
    }

  private:
    int size_;
    std::vector<T> data_;
};

}  //  namespace nono

void solve() {
    int n, m, k;
    std::cin >> n >> m >> k;
    std::vector<int> s(k + 1);
    for (int i = 0; i <= k; i++) std::cin >> s[i];
    for (int i = 0; i <= k; i++) s[i]--;
    constexpr long long INF = 1e18;
    std::vector dist(n, std::vector<long long>(n, INF));
    for (int i = 0; i < m; i++) {
        int u, v, w;
        std::cin >> u >> v >> w;
        u--;
        v--;
        dist[u][v] = w;
        dist[v][u] = w;
    }
    for (int i = 0; i < n; i++) dist[i][i] = 0;
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    nono::FenwickTree<long long> fenwick(k);
    for (int i = 0; i < k; i++) {
        fenwick.add(i, dist[s[i]][s[i + 1]]);
    }
    int q;
    std::cin >> q;
    while (q--) {
        int t, x, y;
        std::cin >> t >> x >> y;
        if (t == 1) {
            y--;
            if (x != 0) {
                long long cur = dist[s[x - 1]][s[x]];
                long long next = dist[s[x - 1]][y];
                fenwick.add(x - 1, next - cur);
            }
            if (x != k) {
                long long cur = dist[s[x]][s[x + 1]];
                long long next = dist[y][s[x + 1]];
                fenwick.add(x, next - cur);
            }
            s[x] = y;
        } else {
            std::cout << fenwick.sum(x, y) << '\n';
        }
    }
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;

    while (t--) solve();
}
0