結果

問題 No.2640 traO Stamps
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-02-29 10:20:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 2,071 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 209,068 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-02-29 10:20:34
合計ジャッジ時間 9,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 140 ms
6,676 KB
testcase_07 AC 154 ms
6,676 KB
testcase_08 AC 163 ms
6,676 KB
testcase_09 AC 141 ms
6,676 KB
testcase_10 AC 148 ms
6,676 KB
testcase_11 AC 163 ms
6,676 KB
testcase_12 AC 147 ms
6,676 KB
testcase_13 AC 130 ms
6,676 KB
testcase_14 AC 158 ms
6,676 KB
testcase_15 AC 150 ms
6,676 KB
testcase_16 AC 133 ms
6,676 KB
testcase_17 AC 141 ms
6,676 KB
testcase_18 AC 153 ms
6,676 KB
testcase_19 AC 154 ms
6,676 KB
testcase_20 AC 148 ms
6,676 KB
testcase_21 AC 142 ms
6,676 KB
testcase_22 AC 183 ms
6,676 KB
testcase_23 AC 144 ms
6,676 KB
testcase_24 AC 149 ms
6,676 KB
testcase_25 AC 145 ms
6,784 KB
testcase_26 AC 156 ms
6,784 KB
testcase_27 AC 159 ms
6,784 KB
testcase_28 AC 151 ms
6,784 KB
testcase_29 AC 205 ms
6,784 KB
testcase_30 AC 170 ms
6,676 KB
testcase_31 AC 168 ms
6,676 KB
testcase_32 AC 160 ms
6,676 KB
testcase_33 AC 162 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<class T> struct BIT {
    private:
        vector<T> bit; int N;
        T _sum(int r){
            r++; T res = 0;
            while(r > 0) res += bit[r-1], r -= r & -r;
            return res;
        }

    public:
        BIT (int n){ N = n; bit.resize(N);}
        BIT (vector<T> &a) : BIT(a.size()) { for (int i=0; i<N; i++) add(i, a[i]);}
        void add(int loc, T val){
            loc++;
            while(loc <= N) bit[loc-1] += val, loc += loc & -loc;
        }
        void change(int loc, T val){add(loc, -get(loc)+val);}
        T sum(int l, int r) {return _sum(r) - _sum(l-1);}
        T get(int l) {return sum(l, l);}
        void clear() {for (int i=0; i<N; i++) bit[i] = 0;}
};

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

    ll N, M, K, a, b, c;
    cin >> N >> M >> K;
    vector<ll> v(K+1); //スタンプiがどこにあるか?
    for (int i=0; i<=K; i++) cin >> v[i];
    vector dist(N+1, vector<ll>(N+1, 1e18)); //dist[i][j] = 頂点iから頂点jまでの最短距離

    for (int i=1; i<=N; i++) dist[i][i] = 0;
    
    for (int i=0; i<M; i++){
        cin >> a >> b >> c;
        dist[a][b] = min(c, dist[a][b]);
        dist[b][a] = min(c, dist[b][a]);
    }

    for (int k=1; k<=N; k++){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }

    BIT<ll> bit(K); //スタンプiからスタンプi+1までの最短距離の総和
    for (int i=0; i<K; i++){
        bit.add(i, dist[v[i]][v[i+1]]);
    }

    ll q, t, x, y;
    cin >> q;
    while(q--){
        cin >> t >> x >> y;
        if (t == 1){
            v[x] = y;
            if (x > 0){
                bit.change(x-1, dist[v[x-1]][v[x]]);
            }
            if (x < K){
                bit.change(x, dist[v[x]][v[x+1]]);
            }
        }
        else{
            cout << bit.sum(x, y-1) << endl;
        }
    }

    return 0;
}
0