結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 WA -
testcase_05 WA -
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 AC 158 ms
6,784 KB
testcase_27 AC 161 ms
6,784 KB
testcase_28 AC 155 ms
6,784 KB
testcase_29 AC 199 ms
6,784 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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=0; 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