結果

問題 No.2640 traO Stamps
ユーザー GOTKAKOGOTKAKO
提出日時 2024-02-19 21:54:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 2,487 bytes
コンパイル時間 3,145 ms
コンパイル使用メモリ 214,456 KB
実行使用メモリ 10,132 KB
最終ジャッジ日時 2024-02-19 21:54:37
合計ジャッジ時間 10,902 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 172 ms
9,416 KB
testcase_07 AC 193 ms
9,316 KB
testcase_08 AC 201 ms
9,804 KB
testcase_09 AC 177 ms
6,912 KB
testcase_10 AC 190 ms
9,784 KB
testcase_11 AC 163 ms
7,040 KB
testcase_12 AC 180 ms
9,856 KB
testcase_13 AC 157 ms
7,168 KB
testcase_14 AC 191 ms
9,856 KB
testcase_15 AC 186 ms
7,168 KB
testcase_16 AC 161 ms
9,756 KB
testcase_17 AC 172 ms
9,796 KB
testcase_18 AC 181 ms
7,168 KB
testcase_19 AC 187 ms
9,932 KB
testcase_20 AC 176 ms
9,852 KB
testcase_21 AC 170 ms
7,168 KB
testcase_22 AC 186 ms
9,900 KB
testcase_23 AC 176 ms
6,912 KB
testcase_24 AC 179 ms
7,040 KB
testcase_25 AC 170 ms
10,008 KB
testcase_26 AC 179 ms
10,132 KB
testcase_27 AC 185 ms
10,132 KB
testcase_28 AC 174 ms
10,132 KB
testcase_29 AC 196 ms
10,132 KB
testcase_30 AC 200 ms
9,996 KB
testcase_31 AC 207 ms
10,076 KB
testcase_32 AC 190 ms
9,644 KB
testcase_33 AC 230 ms
9,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using SS = long long;
class SegmentTree{
    public:
    int siz = 1;
    vector<SS> dat;
 
    SS op(SS a, SS b){return a+b;}
    SS e(){return 0;}
    void renew (SS &a,SS x){
        //a = op(a,x);
        a = x;
        //その他.
    }
 
    void make(int N){
        while(siz < N) siz *= 2;
        dat.resize(siz*2,e());
    }
 
    void make2(int N,vector<SS> &A){
        make(N);
        for(int i=0; i<N; i++){
            int pos = i+siz-1;
            dat.at(pos) = A.at(i);
        }
        for(int i=siz-2; i>=0; i--) dat.at(i) = op(dat.at(i*2+1),dat.at(i*2+2));
    }
 
    void update(int pos,SS x){
        pos = pos+siz-1;
        renew(dat.at(pos),x);
        while(pos != 0){
            pos = (pos-1)/2;
            dat.at(pos) = op(dat.at(pos*2+1),dat.at(pos*2+2));
        }
    }
 
    SS findans(int L, int R, int a, int b, int u){
        if(R <= a || b <= L) return e();
        if(L <= a && b <= R) return dat.at(u);
 
        return op(findans(L,R,a,(a+b)/2,u*2+1),findans(L,R,(a+b)/2,b,u*2+2));
    }
 
    SS get(int pos){return dat.at(pos+siz-1);}
    SS rangeans(int l, int r){return findans(l,r,0,siz,0);}
    SS allrange(){return findans(0,siz,0,siz,0);}
 
    //ノーマルセグ木 二分探索は実装してない.
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M,K; cin >> N >> M >> K;
    vector<int> S(K+1);
    for(auto &s : S) cin >> s,s--;

    long long inf = 1e18;
    vector<vector<long long>> dist(N,vector<long long>(N,inf));
    for(int i=0; i<M; i++){
        int u,v; cin >> u >> v;
        u--; v--;
        int w; cin >> w;
        dist.at(u).at(v) = w;
        dist.at(v).at(u) = w;
    }  
    for(int i=0; i<N; i++) dist.at(i).at(i) = 0;

    for(int l=0; l<N; l++){
        for(int i=0; i<N; i++) for(int k=0; k<N; k++){
            dist.at(i).at(k) = min(dist.at(i).at(k),dist.at(i).at(l)+dist.at(l).at(k));
        }
    }

    vector<long long> time(K);
    for(int i=0; i<K; i++){
        int u = S.at(i),v = S.at(i+1);
        time.at(i) = dist.at(u).at(v);
    }

    SegmentTree Z; Z.make2(K,time);

    int Q; cin >> Q;
    while(Q--){
        int t,x,y; cin >> t >> x >> y;
        if(t == 1){
            y--;
            if(x) Z.update(x-1,dist.at(S.at(x-1)).at(y));
            if(x != K) Z.update(x,dist.at(y).at(S.at(x+1)));
            S.at(x) = y;
        }
        if(t == 2) cout << Z.rangeans(x,y) << endl;
    }
}
0