結果

問題 No.2640 traO Stamps
ユーザー noya2noya2
提出日時 2024-02-13 23:15:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 5,142 ms
コンパイル使用メモリ 313,636 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-13 23:15:36
合計ジャッジ時間 10,334 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 62 ms
6,676 KB
testcase_07 AC 61 ms
6,676 KB
testcase_08 AC 67 ms
6,676 KB
testcase_09 AC 52 ms
6,676 KB
testcase_10 AC 66 ms
6,676 KB
testcase_11 AC 53 ms
6,676 KB
testcase_12 AC 60 ms
6,676 KB
testcase_13 AC 54 ms
6,676 KB
testcase_14 AC 70 ms
6,676 KB
testcase_15 AC 59 ms
6,676 KB
testcase_16 AC 57 ms
6,676 KB
testcase_17 AC 62 ms
6,676 KB
testcase_18 AC 78 ms
6,676 KB
testcase_19 AC 65 ms
6,676 KB
testcase_20 AC 74 ms
6,676 KB
testcase_21 AC 61 ms
6,676 KB
testcase_22 AC 68 ms
6,676 KB
testcase_23 AC 54 ms
6,676 KB
testcase_24 AC 61 ms
6,676 KB
testcase_25 AC 67 ms
6,676 KB
testcase_26 AC 60 ms
6,676 KB
testcase_27 AC 60 ms
6,676 KB
testcase_28 AC 58 ms
6,676 KB
testcase_29 AC 63 ms
6,676 KB
testcase_30 AC 74 ms
6,676 KB
testcase_31 AC 87 ms
6,676 KB
testcase_32 AC 68 ms
6,676 KB
testcase_33 AC 70 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T>
bool chmin(T &a, const T &b){
    if (a <= b) return false;
    a = b;
    return true;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k; cin >> n >> m >> k;
    vector<vector<ll>> dist(n,vector<ll>(n,linf));
    for (int i = 0; i < n; i++){
        dist[i][i] = 0;
    }
    vector<int> s(k+1);
    for (int i = 0; i <= k; i++){
        int v; cin >> v; v--;
        s[i] = v;
    }
    for (int i = 0; i < m; i++){
        int u, v; cin >> u >> v; u--, v--;
        ll w; cin >> w;
        chmin(dist[u][v],w);
        chmin(dist[v][u],w);
    }
    for (int l = 0; l < n; l++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++){
        chmin(dist[i][j],dist[i][l]+dist[l][j]);
    }
    atcoder::fenwick_tree<ll> fen(k);
    auto set = [&](int i, ll x){
        ll d = x - fen.sum(i,i+1);
        fen.add(i,d);
    };
    for (int i = 0; i < k; i++){
        set(i,dist[s[i]][s[i+1]]);
    }
    int q; cin >> q;
    while (q--){
        int t, x, y; cin >> t >> x >> y;
        if (t == 1){
            y--;
            s[x] = y;
            if (x > 0){
                set(x-1,dist[s[x-1]][s[x]]);
            }
            if (x < k){
                set(x,dist[s[x]][s[x+1]]);
            }
        }
        if (t == 2){
            cout << fen.sum(x,y) << '\n';
        }
    }
}
0