結果

問題 No.2640 traO Stamps
ユーザー otoshigootoshigo
提出日時 2024-02-19 21:59:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,747 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 85,280 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2024-02-19 21:59:51
合計ジャッジ時間 5,752 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 70 ms
9,288 KB
testcase_07 AC 70 ms
9,188 KB
testcase_08 AC 79 ms
9,676 KB
testcase_09 AC 62 ms
6,784 KB
testcase_10 AC 77 ms
9,656 KB
testcase_11 AC 63 ms
6,912 KB
testcase_12 AC 73 ms
9,728 KB
testcase_13 AC 65 ms
7,040 KB
testcase_14 AC 80 ms
9,728 KB
testcase_15 AC 67 ms
7,040 KB
testcase_16 AC 64 ms
9,628 KB
testcase_17 AC 72 ms
9,668 KB
testcase_18 AC 68 ms
7,040 KB
testcase_19 AC 76 ms
9,804 KB
testcase_20 AC 76 ms
9,724 KB
testcase_21 AC 66 ms
7,040 KB
testcase_22 AC 80 ms
9,772 KB
testcase_23 AC 64 ms
6,784 KB
testcase_24 AC 68 ms
6,912 KB
testcase_25 AC 75 ms
9,880 KB
testcase_26 AC 65 ms
10,004 KB
testcase_27 AC 65 ms
10,004 KB
testcase_28 AC 64 ms
10,004 KB
testcase_29 AC 71 ms
10,004 KB
testcase_30 AC 87 ms
9,868 KB
testcase_31 AC 86 ms
9,948 KB
testcase_32 AC 78 ms
9,516 KB
testcase_33 AC 80 ms
9,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

template <typename M>
struct segment_tree {
    using T = typename M::T;

public:
    explicit segment_tree(int N) : segment_tree(std::vector<T>(N, M::e())) {}

    explicit segment_tree(const std::vector<T>& v) {
        int N = (int)v.size();
        n = N;
        size = 1;
        while (size < N) size <<= 1;
        data.resize(2 * size, M::e());
        for (int i = 0; i < N; i++) data[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) update(i);
    };

    void set(int p, T x) {
        assert(0 <= p && p < n);
        p += size;
        data[p] = x;
        while (p > 1) {
            p >>= 1;
            update(p);
        }
    }

    T get(int p) {
        assert(0 <= p && p < n);
        p += size;
        return data[p];
    }

    T prod(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        T vl = M::e(), vr = M::e();
        l += size;
        r += size;
        while (l < r) {
            if (l & 1) vl = M::op(vl, data[l++]);
            if (r & 1) vr = M::op(data[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(vl, vr);
    }

    T all_prod() { return data[1]; }

private:
    int n, size;
    std::vector<T> data;
    void update(int p) { data[p] = M::op(data[2 * p], data[2 * p + 1]); }
};

struct Monoid{
    using T=ll;
    static T op(T l,T r){return l+r;}
    static T e(){return 0;}
};

const ll INF=1LL<<60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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 D(N,vector<ll>(N,INF));
    for(int i=0;i<N;i++)D[i][i]=0;
    for(int i=0;i<M;i++){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--;
        b--;
        D[a][b]=c;
        D[b][a]=c;
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                chmin(D[i][j],D[i][k]+D[k][j]);
            }
        }
    }
    segment_tree<Monoid>seg(K);
    for(int i=0;i<K;i++)seg.set(i,D[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)seg.set(x-1,D[S[x-1]][S[x]]);
            if(x+1<=K)seg.set(x,D[S[x]][S[x+1]]);
        }else{
            cout<<seg.prod(x,y)<<"\n";
        }
    }
}
0