結果
問題 | No.2640 traO Stamps |
ユーザー |
![]() |
提出日時 | 2024-02-19 21:40:20 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,097 bytes |
コンパイル時間 | 1,341 ms |
コンパイル使用メモリ | 135,732 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-29 01:35:41 |
合計ジャッジ時間 | 5,547 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 31 WA * 2 |
ソースコード
#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(); }