結果

問題 No.900 aδδitivee
ユーザー t98slidert98slider
提出日時 2023-05-01 00:31:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 4,205 ms
コンパイル使用メモリ 238,424 KB
実行使用メモリ 28,236 KB
最終ジャッジ日時 2023-08-12 12:47:34
合計ジャッジ時間 9,211 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 123 ms
24,256 KB
testcase_08 AC 120 ms
24,156 KB
testcase_09 AC 118 ms
24,012 KB
testcase_10 AC 125 ms
24,044 KB
testcase_11 AC 131 ms
24,256 KB
testcase_12 AC 118 ms
23,988 KB
testcase_13 AC 124 ms
24,092 KB
testcase_14 AC 121 ms
24,192 KB
testcase_15 AC 118 ms
24,068 KB
testcase_16 AC 117 ms
23,900 KB
testcase_17 AC 118 ms
24,212 KB
testcase_18 AC 118 ms
23,956 KB
testcase_19 AC 116 ms
24,208 KB
testcase_20 AC 121 ms
23,872 KB
testcase_21 AC 114 ms
23,936 KB
testcase_22 AC 107 ms
28,236 KB
testcase_23 AC 109 ms
28,220 KB
testcase_24 AC 111 ms
28,124 KB
testcase_25 AC 112 ms
28,216 KB
testcase_26 AC 110 ms
28,164 KB
testcase_27 AC 116 ms
28,212 KB
testcase_28 AC 117 ms
28,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
        }
    }
}
0