結果

問題 No.2640 traO Stamps
ユーザー shobonvipshobonvip
提出日時 2024-02-19 22:39:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 4,249 ms
コンパイル使用メモリ 267,572 KB
実行使用メモリ 10,132 KB
最終ジャッジ日時 2024-02-19 22:39:17
合計ジャッジ時間 8,795 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 63 ms
9,416 KB
testcase_07 AC 62 ms
9,316 KB
testcase_08 AC 69 ms
9,804 KB
testcase_09 AC 53 ms
6,912 KB
testcase_10 AC 68 ms
9,784 KB
testcase_11 AC 55 ms
7,040 KB
testcase_12 AC 67 ms
9,856 KB
testcase_13 AC 59 ms
7,168 KB
testcase_14 AC 72 ms
9,856 KB
testcase_15 AC 60 ms
7,168 KB
testcase_16 AC 59 ms
9,756 KB
testcase_17 AC 66 ms
9,796 KB
testcase_18 AC 61 ms
7,168 KB
testcase_19 AC 67 ms
9,932 KB
testcase_20 AC 70 ms
9,852 KB
testcase_21 AC 61 ms
7,168 KB
testcase_22 AC 70 ms
9,900 KB
testcase_23 AC 60 ms
6,912 KB
testcase_24 AC 61 ms
7,040 KB
testcase_25 AC 67 ms
10,008 KB
testcase_26 AC 57 ms
10,132 KB
testcase_27 AC 58 ms
10,132 KB
testcase_28 AC 58 ms
10,132 KB
testcase_29 AC 63 ms
10,132 KB
testcase_30 AC 80 ms
9,996 KB
testcase_31 AC 75 ms
10,076 KB
testcase_32 AC 73 ms
9,644 KB
testcase_33 AC 75 ms
9,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

ll op(ll a, ll b) {return a + b;}
ll e(){return 0;}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m, k; cin >> n >> m >> k;
	vector d(n, vector<ll>(n, 1e18));

	vector<int> s(k+1);
	rep(i,0,k+1){
		cin >> s[i];
		s[i]--;
	}

	rep(i,0,n) d[i][i] = 0;

	rep(i,0,m){
		int a, b; cin >> a >> b;
		a--; b--;
		ll c; cin >> c;
		chmin(d[a][b], c);
		chmin(d[b][a], c);
	}

	rep(r,0,n){
		rep(i,0,n){
			rep(j,0,n){
				chmin(d[i][j], d[i][r] + d[r][j]);
			}
		}
	}


	segtree<ll,op,e> seg(k);

	rep(i,0,k){
		seg.set(i, d[s[i]][s[i+1]]);
	}

	int q; cin >> q;
	while(q--){
		int t; cin >> t;
		int x, y; cin >> x >> y;
		if (t == 1){
			s[x] = y-1;
			if (x-1 >= 0){
				seg.set(x-1, d[s[x-1]][s[x]]);
			}
			if (x < k){
				seg.set(x, d[s[x]][s[x+1]]);
			}
		}else{
			cout << seg.prod(x, y) << '\n';
		}
	}
	
}

0