結果

問題 No.2640 traO Stamps
ユーザー kokoseikokosei
提出日時 2024-02-19 21:59:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,551 bytes
コンパイル時間 3,113 ms
コンパイル使用メモリ 251,116 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2024-02-19 21:59:33
合計ジャッジ時間 8,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 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 75 ms
9,400 KB
testcase_07 AC 76 ms
9,312 KB
testcase_08 AC 84 ms
9,696 KB
testcase_09 AC 65 ms
6,912 KB
testcase_10 AC 81 ms
9,776 KB
testcase_11 AC 68 ms
7,040 KB
testcase_12 AC 78 ms
9,916 KB
testcase_13 AC 64 ms
7,040 KB
testcase_14 AC 85 ms
9,696 KB
testcase_15 AC 71 ms
7,168 KB
testcase_16 AC 72 ms
9,724 KB
testcase_17 AC 77 ms
9,704 KB
testcase_18 AC 71 ms
7,168 KB
testcase_19 AC 85 ms
9,928 KB
testcase_20 AC 82 ms
9,836 KB
testcase_21 AC 73 ms
7,168 KB
testcase_22 AC 84 ms
9,868 KB
testcase_23 AC 79 ms
6,912 KB
testcase_24 AC 72 ms
6,912 KB
testcase_25 AC 82 ms
9,928 KB
testcase_26 AC 66 ms
10,004 KB
testcase_27 AC 67 ms
10,004 KB
testcase_28 AC 65 ms
10,004 KB
testcase_29 AC 70 ms
10,004 KB
testcase_30 AC 91 ms
9,916 KB
testcase_31 AC 91 ms
9,988 KB
testcase_32 AC 85 ms
9,564 KB
testcase_33 AC 85 ms
9,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll op(ll a, ll b) { return a + b; }
ll e() { return 0; }
using segtree = atcoder::segtree<ll, op, e>;

int N, M, K, Q;
int S[200010];
ll dist[210][210];
template<typename A, int N, typename T>
void Fill(A (&arr)[N], const T &val){
    fill((T*)arr, (T*)(arr + N), val);
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N >> M >> K;
    Fill(dist, inf);
    for(int i = 0;i <= K;i++){
        cin >> S[i]; S[i]--;
    }
    for(int i = 0;i < N;i++)dist[i][i] = 0;
    for(int i = 0;i < M;i++){
        int a, b; ll c; cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }
    for(int k = 0;k < N;k++){
        for(int i = 0;i < N;i++){
            for(int j = 0;j < N;j++){
                dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
            }
        }
    }
    segtree seg(K);
    for(int i = 0;i < K;i++){
        seg.set(i, dist[S[i]][S[i + 1]]);
    }
    cin >> Q;
    while(Q--){
        int t; cin >> t;
        if(t == 1){
            int x, y; cin >> x >> y;
            y--;
            S[x] = y;
            if(x > 0){
                seg.set(x - 1, dist[S[x - 1]][S[x]]);
            }
            if(x < K){
                seg.set(x, dist[S[x]][S[x + 1]]);
            }
        }else{
            int x, y; cin >> x >> y;
            cout << seg.prod(x, y) << "\n";
        }
    }
    return 0;
}
0