結果

問題 No.2640 traO Stamps
ユーザー ayataka5ayataka5
提出日時 2024-02-19 22:26:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,392 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 209,712 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-02-19 22:26:22
合計ジャッジ時間 11,441 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

const long long INF = (1LL << 60);

/* segment tree (noncommutative monoid-compatible) */
/*
    References:
    https://hcpc-hokudai.github.io/archive/structure_segtree_001.pdf
    https://hackmd.io/@tatyam-prime/rkA5wJMdo
    https://github.com/atcoder/ac-library/blob/master/atcoder/segtree.hpp  
*/

template<typename T>
struct SegmentTree {
    int n;
    vector<T> seg;

    /* ===== change here ===== */

    T op(T a, T b) { return a + b; }

    T e() { return 0; }

    /* ===== ===== ===== ===== */

    SegmentTree(int n): n(n), seg(n * 2, e()) {}

    T operator[](int i) const {
        return seg[n + i];
    }

    void set(int i, T x) {
        i += n;
        seg[i] = x;
        while(1 < i) {
            i >>= 1;
            seg[i] = op(seg[i << 1 | 0], seg[i << 1 | 1]);
        }
    }

    T prod(int l, int r) {
        T ansL(e()), ansR=(e());
        for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) ansL = op(ansL, seg[l++]);
            if(r & 1) ansR = op(seg[--r], ansR);
        }
        return op(ansL, ansR);
    }

    T all_prod() {
        return prod(0, n);
    }
};

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector S(K+1, 0);
    for(int i = 0; i < K+1; i++) { cin >> S[i]; S[i]--; }
    vector A(M, 0), B(M, 0);
    vector C(M, 0LL);
    vector dist(N, vector(N, INF));
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i]; A[i]--, B[i]--;
        dist[A[i]][B[i]] = C[i];
        dist[B[i]][A[i]] = C[i];
    }
    int Q;
    cin >> Q;
    vector T(Q, 0), X(Q, 0), Y(Q, 0);
    for(int i = 0; i < Q; i++) cin >> T[i] >> X[i] >> Y[i];
    for(int k = 0; k < N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                if(dist[i][k] < INF && dist[k][j] < INF) dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
            }
        }
    }
    SegmentTree<long long> segtree(K);
    for(int i = 0; i < K; i++) { segtree.set(i, dist[S[i]][S[i+1]]); }
    for(int i = 0; i < Q; i++) {
        if(T[i] == 1) {
            S[X[i]] = --Y[i];
            if(0 <= X[i]-1) segtree.set(X[i]-1, dist[S[X[i]-1]][S[X[i]]]);
            if(X[i]+1 <= K) segtree.set(X[i], dist[S[X[i]]][S[X[i]+1]]);
        }
        if(T[i] == 2) {
            cout << segtree.prod(X[i], Y[i]) << endl;
        }
    }
    return 0;
}
0