結果
問題 |
No.2640 traO Stamps
|
ユーザー |
![]() |
提出日時 | 2024-02-19 21:42:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 2,899 bytes |
コンパイル時間 | 1,332 ms |
コンパイル使用メモリ | 137,096 KB |
最終ジャッジ日時 | 2025-02-19 16:47:21 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
#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"; } } } }