結果

問題 No.2640 traO Stamps
ユーザー ゆにぽけゆにぽけ
提出日時 2024-02-19 21:45:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 2,098 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 135,480 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 21:45:52
合計ジャッジ時間 5,421 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 2 ms
6,676 KB
testcase_06 AC 50 ms
6,676 KB
testcase_07 AC 49 ms
6,676 KB
testcase_08 AC 55 ms
6,676 KB
testcase_09 AC 43 ms
6,676 KB
testcase_10 AC 68 ms
6,676 KB
testcase_11 AC 43 ms
6,676 KB
testcase_12 AC 50 ms
6,676 KB
testcase_13 AC 42 ms
6,676 KB
testcase_14 AC 55 ms
6,676 KB
testcase_15 AC 47 ms
6,676 KB
testcase_16 AC 47 ms
6,676 KB
testcase_17 AC 49 ms
6,676 KB
testcase_18 AC 48 ms
6,676 KB
testcase_19 AC 55 ms
6,676 KB
testcase_20 AC 54 ms
6,676 KB
testcase_21 AC 46 ms
6,676 KB
testcase_22 AC 62 ms
6,676 KB
testcase_23 AC 47 ms
6,676 KB
testcase_24 AC 61 ms
6,676 KB
testcase_25 AC 53 ms
6,676 KB
testcase_26 AC 52 ms
6,676 KB
testcase_27 AC 53 ms
6,676 KB
testcase_28 AC 46 ms
6,676 KB
testcase_29 AC 51 ms
6,676 KB
testcase_30 AC 60 ms
6,676 KB
testcase_31 AC 60 ms
6,676 KB
testcase_32 AC 62 ms
6,676 KB
testcase_33 AC 56 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
template<class T> struct BinaryIndexedTree
{
	private:
	int N;
	vector<T> node;

	public:

	BinaryIndexedTree() : N(0) {}
	BinaryIndexedTree(int N) : N(N), node(N) {}

	void add(int pos,T x)
	{
		assert(0 <= pos && pos < N);
		pos++;
		while(pos <= N)
		{
			node[pos-1] += x;
			pos += pos & -pos;
		}
	}

	T sum(int l,int r)
	{
		assert(0 <= l && l <= N && r <= N);
		return sum(r) - sum(l);
	}

	T sum(int r)
	{
		T ret = 0;
		while(r > 0)
		{
			ret += node[r-1];
			r -= r & -r;
		}
		return ret;
	}

	T sum() {return sum(N);}
	
};

void Main()
{
	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]--;
	}
	vector<vector<long long>> dp(N,vector<long long>(N,(long long)1e18));
	for(int i = 0;i < M;i++)
	{
		int u,v,w;
		cin >> u >> v >> w;
		u--; v--;
		dp[u][v] = dp[v][u] = w;
	}
	for(int i = 0;i < N;i++)
	{
		dp[i][i] = 0;
	}
	for(int k = 0;k < N;k++)
	{
		for(int i = 0;i < N;i++)
		{
			for(int j = 0;j < N;j++)
			{
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
			}
		}
	}
	BinaryIndexedTree<long long> BIT(K);
	for(int i = 0;i < K;i++)
	{
		BIT.add(i,dp[S[i]][S[i + 1]]);
	}
	int Q;
	cin >> Q;
	for(;Q--;)
	{
		int t,x,y;
		cin >> t >> x >> y;
		if(t == 1)
		{
			y--;
			if(x + 1 <= K)
			{
				BIT.add(x,-dp[S[x]][S[x + 1]]);
				BIT.add(x,dp[y][S[x + 1]]);
			}
			if(x > 0)
			{
				BIT.add(x - 1,-dp[S[x - 1]][S[x]]);
				BIT.add(x - 1,dp[S[x - 1]][y]);
			}
			S[x] = y;
		}
		else
		{
			cout << BIT.sum(x,y) << "\n";
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0