結果

問題 No.2640 traO Stamps
ユーザー ripityripity
提出日時 2024-02-19 22:09:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 210,924 KB
実行使用メモリ 10,108 KB
最終ジャッジ日時 2024-02-19 22:09:14
合計ジャッジ時間 11,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 193 ms
9,392 KB
testcase_07 AC 215 ms
9,292 KB
testcase_08 AC 246 ms
9,780 KB
testcase_09 AC 196 ms
6,784 KB
testcase_10 AC 204 ms
9,760 KB
testcase_11 AC 185 ms
7,040 KB
testcase_12 AC 211 ms
9,832 KB
testcase_13 AC 176 ms
7,040 KB
testcase_14 AC 216 ms
9,832 KB
testcase_15 AC 197 ms
7,168 KB
testcase_16 AC 185 ms
9,732 KB
testcase_17 AC 201 ms
9,772 KB
testcase_18 AC 220 ms
7,040 KB
testcase_19 AC 239 ms
9,908 KB
testcase_20 AC 211 ms
9,828 KB
testcase_21 AC 194 ms
7,168 KB
testcase_22 AC 217 ms
9,876 KB
testcase_23 AC 198 ms
6,912 KB
testcase_24 AC 202 ms
7,040 KB
testcase_25 AC 230 ms
9,984 KB
testcase_26 AC 212 ms
10,108 KB
testcase_27 AC 210 ms
10,108 KB
testcase_28 AC 199 ms
10,108 KB
testcase_29 AC 228 ms
10,108 KB
testcase_30 AC 257 ms
9,972 KB
testcase_31 AC 229 ms
10,052 KB
testcase_32 AC 217 ms
9,620 KB
testcase_33 AC 219 ms
9,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/segtree>
using namespace atcoder;

long long op(long long x, long long y) {
    return x+y;
}

long long e() {
    return 0LL;
}

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> S(K+1);
    for( int i = 0; i <= K; i++ ) {
        cin >> S[i];
        S[i]--;
    }
    constexpr long long INF = 1LL<<60;
    vector dist(N, vector<long long>(N, INF));
    for( int i = 0; i < N; i++ ) {
        dist[i][i] = 0;
    }
    for( int i = 0; i < M; i++ ) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = 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][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    segtree<long long, op, e> seg(K);
    for( int i = 0; i < K; i++ ) {
        seg.set(i, dist[S[i]][S[i+1]]);
    }
    int Q;
    cin >> Q;
    for( int i = 0; i < Q; i++ ) {
        int t, x, y;
        cin >> t >> x >> y;
        if( t == 1 ) {
            y--;
            S[x] = y;
            if( x-1 >= 0 ) seg.set(x-1, dist[S[x-1]][S[x]]);
            if( x+1 <= K ) seg.set(x, dist[S[x]][S[x+1]]);
        }
        if( t == 2 ) {
            cout << seg.prod(x, y) << endl;
        }
    }
}
0