結果
問題 | No.2640 traO Stamps |
ユーザー |
👑 |
提出日時 | 2024-02-19 21:50:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,057 ms / 2,000 ms |
コード長 | 3,563 bytes |
コンパイル時間 | 5,029 ms |
コンパイル使用メモリ | 272,348 KB |
最終ジャッジ日時 | 2025-02-19 16:52:52 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} template<typename T> struct Edge_Dijkstra{ int from, to; T cost; Edge_Dijkstra(int from, int to, T cost) : from(from), to(to), cost(cost) {}; }; const long long INF = 1001001001001001; template<typename T> struct Dijkstra{ int n, m; vector<bool> initialized; vector<Edge_Dijkstra<T>> E; vector<vector<int>> G; map<int, vector<T>> dist; map<int, vector<int>> idx; Dijkstra(int _n) : n(_n), m(0), initialized(n, false), G(n){} void add_edge(int from, int to, T cost){ Edge_Dijkstra e(from, to, cost); E.push_back(e); G[from].emplace_back(m); m++; } void calc(int s){ initialized[s] = true; dist[s] = vector<T>(n, INF); idx[s] = vector<int>(n, -1); priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> pq; pq.emplace(0, s, -1); while(pq.size()){ auto [cost, from, index] = pq.top(); pq.pop(); if(dist[s][from] <= cost) continue; dist[s][from] = cost; idx[s][from] = index; for(int index : G[from]){ int to = E[index].to; T cost_plus = E[index].cost; if(dist[s][to] <= cost + cost_plus) continue; pq.emplace(cost + cost_plus, to, index); } } } int farthest(int s){ if(!initialized[s]) calc(s); int idx = 0; rep(i, n) if(dist[s][i] > dist[s][idx]) idx = i; return idx; } T get_dist(int s, int t){ if(!initialized[s]) calc(s); return dist[s][t]; } vi restore(int s, int t){ if(!initialized[s]) calc(s); if(dist[s][t] == INF) return vi(0); vi res; while(idx[s][t] != -1){ auto e = E[idx[s][t]]; res.push_back(idx[s][t]); t = e.from; } reverse(res.begin(), res.end()); return res; } }; using S = long long; S op(S a, S b){return a + b;} S e(){return 0LL;} int main(){ int n, m, k; cin >> n >> m >> k; vector<int> s(k + 1); cin >> s; rep(i, k + 1) s[i]--; Dijkstra<long long> graph(n); rep(i, m){ int a, b, c; cin >> a >> b >> c; a--; b--; graph.add_edge(a, b, c); graph.add_edge(b, a, c); } segtree<S, op, e> seg(k); rep(i, k) seg.set(i, graph.get_dist(s[i], s[i + 1])); int q; cin >> q; rep(_, q){ int t, x, y; cin >> t >> x >> y; if(t == 1){ y--; s[x] = y; if(x > 0) seg.set(x - 1, graph.get_dist(s[x - 1], s[x])); if(x < k) seg.set(x, graph.get_dist(s[x], s[x + 1])); } if(t == 2){ auto res = seg.prod(x, y); cout << res << "\n"; } } return 0; }