結果

問題 No.2640 traO Stamps
ユーザー ponjuiceponjuice
提出日時 2024-02-13 17:06:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,350 bytes
コンパイル時間 4,339 ms
コンパイル使用メモリ 267,180 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-13 17:06:58
合計ジャッジ時間 12,245 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 AC 134 ms
6,676 KB
testcase_07 AC 156 ms
6,676 KB
testcase_08 AC 156 ms
6,676 KB
testcase_09 AC 138 ms
6,676 KB
testcase_10 AC 143 ms
6,676 KB
testcase_11 AC 130 ms
6,676 KB
testcase_12 AC 144 ms
6,676 KB
testcase_13 AC 126 ms
6,676 KB
testcase_14 AC 160 ms
6,676 KB
testcase_15 AC 143 ms
6,676 KB
testcase_16 AC 136 ms
6,676 KB
testcase_17 AC 138 ms
6,676 KB
testcase_18 AC 147 ms
6,676 KB
testcase_19 AC 148 ms
6,676 KB
testcase_20 AC 143 ms
6,676 KB
testcase_21 AC 171 ms
6,676 KB
testcase_22 AC 151 ms
6,676 KB
testcase_23 AC 139 ms
6,676 KB
testcase_24 AC 144 ms
6,676 KB
testcase_25 AC 144 ms
6,676 KB
testcase_26 AC 158 ms
6,676 KB
testcase_27 AC 186 ms
6,676 KB
testcase_28 AC 153 ms
6,676 KB
testcase_29 AC 177 ms
6,676 KB
testcase_30 AC 163 ms
6,676 KB
testcase_31 AC 161 ms
6,676 KB
testcase_32 AC 154 ms
6,676 KB
testcase_33 AC 181 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> s(k+1);
    for(int i = 0; i < k + 1; i++) {
        cin >> s[i];
        s[i]--;
    }
    vector<vector<ll>> wf(n, vector<ll>(n, LONG_MAX >> 1));
    for(int i = 0; i < n; i++) wf[i][i] = 0;
    
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--,b--;
        wf[a][b] = c;
        wf[b][a] = c;
    }

    for(int l = 0; l < n; l++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                wf[i][j] = min(wf[i][j], wf[i][l] + wf[l][j]);
            }
        }
    }

    fenwick_tree<ll> tree(k);
    for(int i = 0; i < k; i++){
        tree.add(i, wf[s[i]][s[i+1]]);
    }

    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int x, y;
            cin >> x >> y;
            y--;
            if(x != 0) tree.add(x-1, wf[s[x-1]][y] - wf[s[x-1]][s[x]]);
            if(x != k) tree.add(x, wf[y][s[x+1]] - wf[s[x]][s[x+1]]);
            s[x] = y;
        }
        if(t == 2){
            int x,y;
            cin >> x >> y;
            cout << tree.sum(x, y) << endl;
        }
    }
}
0