結果

問題 No.2640 traO Stamps
ユーザー ぷらぷら
提出日時 2024-02-19 21:42:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 2,899 bytes
コンパイル時間 1,275 ms
コンパイル使用メモリ 142,260 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 21:42:34
合計ジャッジ時間 5,445 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 52 ms
6,676 KB
testcase_07 AC 51 ms
6,676 KB
testcase_08 AC 58 ms
6,676 KB
testcase_09 AC 45 ms
6,676 KB
testcase_10 AC 57 ms
6,676 KB
testcase_11 AC 46 ms
6,676 KB
testcase_12 AC 57 ms
6,676 KB
testcase_13 AC 47 ms
6,676 KB
testcase_14 AC 60 ms
6,676 KB
testcase_15 AC 54 ms
6,676 KB
testcase_16 AC 50 ms
6,676 KB
testcase_17 AC 53 ms
6,676 KB
testcase_18 AC 50 ms
6,676 KB
testcase_19 AC 57 ms
6,676 KB
testcase_20 AC 56 ms
6,676 KB
testcase_21 AC 48 ms
6,676 KB
testcase_22 AC 62 ms
6,676 KB
testcase_23 AC 50 ms
6,676 KB
testcase_24 AC 54 ms
6,676 KB
testcase_25 AC 57 ms
6,676 KB
testcase_26 AC 49 ms
6,676 KB
testcase_27 AC 49 ms
6,676 KB
testcase_28 AC 49 ms
6,676 KB
testcase_29 AC 53 ms
6,676 KB
testcase_30 AC 63 ms
6,676 KB
testcase_31 AC 63 ms
6,676 KB
testcase_32 AC 59 ms
6,676 KB
testcase_33 AC 60 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

long long inf = 1001001001001001001;

long long dist[220][220];

void chmin(long long &x,long long y) {
    if(x > y) {
        x = y;
    }
}

template <typename T>
struct BinaryIndexedTree {
    int N;
    vector<T>bit;
    BinaryIndexedTree(){}
    BinaryIndexedTree(int x) {
        N = x;
        bit.resize(x+1);
    }
    void add(int x,T y) {
        x++;
        while(x <= N) {
            bit[x] += y;
            x += x&-x;
        }
    }
    T sum(int x) {
        x++;
        T res = 0;
        while(x) {
            res += bit[x];
            x -= x&-x;
        }
        return res;
    }
    inline T sum(int l, int r) {//[l,r)
        return sum(r-1)-sum(l-1);
    }
    inline T operator[](int k) {
        return sum(k)-sum(k-1);
    }
};

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; i++) {
        cin >> S[i];
        S[i]--;
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            dist[i][j] = inf;
        }
        dist[i][i] = 0;
    }
    for(int i = 0; i < M; i++) {
        int A,B,C;
        cin >> A >> B >> C;
        A--;
        B--;
        chmin(dist[A][B],C);
        chmin(dist[B][A],C);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                chmin(dist[j][k],dist[j][i]+dist[i][k]);
            }
        }
    }
    BinaryIndexedTree<long long>bit(K);
    for(int i = 0; i < K; i++) {
        bit.add(i,dist[S[i]][S[i+1]]);
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int T,X,Y;
        cin >> T >> X >> Y;
        if(T == 1) {
            Y--;
            for(int i = -1; i <= 0; i++) {
                int nx = X+i,ny = X+i+1;
                if(nx >= 0 && ny <= K) {
                    bit.add(nx,-bit[nx]);
                }
            }
            S[X] = Y;
            for(int i = -1; i <= 0; i++) {
                int nx = X+i,ny = X+i+1;
                if(nx >= 0 && ny <= K) {
                    bit.add(nx,dist[S[nx]][S[ny]]);
                }
            }
        }
        if(T == 2) {
            if(X == Y) {
                cout << 0 << "\n";
            }
            else {
                cout << bit.sum(X,Y) << "\n";
            }
        }
    }
}
0