結果
| 問題 | No.2640 traO Stamps |
| コンテスト | |
| ユーザー |
ゆにぽけ
|
| 提出日時 | 2024-02-19 21:45:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 2,098 bytes |
| 記録 | |
| コンパイル時間 | 1,360 ms |
| コンパイル使用メモリ | 131,180 KB |
| 最終ジャッジ日時 | 2025-02-19 16:49:34 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
ソースコード
#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();
}
ゆにぽけ