結果
問題 | No.900 aδδitivee |
ユーザー |
|
提出日時 | 2023-05-01 00:31:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 150 ms / 2,000 ms |
コード長 | 1,492 bytes |
コンパイル時間 | 4,343 ms |
コンパイル使用メモリ | 239,972 KB |
実行使用メモリ | 28,416 KB |
最終ジャッジ日時 | 2024-11-19 14:13:13 |
合計ジャッジ時間 | 9,407 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using ll = long long; using S = pair<ll, int>; using F = ll; S e(){return make_pair(0, 0);} S op(S l,S r){return make_pair(l.first + r.first, l.second + r.second);} S mapping(F f, S x){return make_pair(x.first + x.second * f, x.second);} F composition(F f, F g){return f + g;} F id(){return 0;} int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, u, v, w, Q; cin >> n; vector<vector<pair<int, int>>> g(n); for(int i = 1; i < n; i++){ cin >> u >> v >> w; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } int timer = 0; vector<int> depth(n), ent(n), ext(n), weight(n); vector<pair<ll,int>> tmp(2 * n); function<void(int, int)> dfs = [&](int v, int p){ tmp[timer] = make_pair(weight[v], 1); ent[v] = timer++; for(auto &&pa : g[v]){ tie(u, w) = pa; if(u == p) continue; depth[u] = depth[v] + 1; weight[u] = w; dfs(u, v); } tmp[timer] = make_pair(-weight[v], -1); ext[v] = timer++; }; dfs(0, -1); atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(tmp); cin >> Q; while(Q--){ int cmd, v, x; cin >> cmd >> v; if(cmd == 1){ cin >> x; seg.apply(ent[v] + 1, ext[v], x); }else{ cout << seg.prod(0, ent[v] + 1).first << '\n'; } } }