結果

問題 No.900 aδδitivee
ユーザー kwm_tkwm_t
提出日時 2023-05-06 20:06:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 2,084 bytes
コンパイル時間 5,036 ms
コンパイル使用メモリ 268,456 KB
実行使用メモリ 26,648 KB
最終ジャッジ日時 2023-08-15 17:39:53
合計ジャッジ時間 11,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 128 ms
23,648 KB
testcase_08 AC 133 ms
23,604 KB
testcase_09 AC 130 ms
23,628 KB
testcase_10 AC 133 ms
23,716 KB
testcase_11 AC 130 ms
23,740 KB
testcase_12 AC 133 ms
23,596 KB
testcase_13 AC 135 ms
23,720 KB
testcase_14 AC 136 ms
23,596 KB
testcase_15 AC 134 ms
23,740 KB
testcase_16 AC 131 ms
23,732 KB
testcase_17 AC 131 ms
23,712 KB
testcase_18 AC 136 ms
23,576 KB
testcase_19 AC 134 ms
23,664 KB
testcase_20 AC 132 ms
23,612 KB
testcase_21 AC 133 ms
23,892 KB
testcase_22 AC 122 ms
26,616 KB
testcase_23 AC 123 ms
26,508 KB
testcase_24 AC 124 ms
26,500 KB
testcase_25 AC 122 ms
26,624 KB
testcase_26 AC 130 ms
26,572 KB
testcase_27 AC 127 ms
26,648 KB
testcase_28 AC 123 ms
26,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
// 区間加算・区間和取得
struct S {
	long long value;
	int size;
};
using F = long long;

S op(S a, S b) { return { a.value + b.value, a.size + b.size }; }
S e() { return { 0, 0 }; }
S mapping(F f, S x) { return { x.value + f * x.size, x.size }; }
F composition(F f, F g) { return f + g; }
F id() { return 0; }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<vector<pair<int, int>>> to(n);
	rep(i, n - 1) {
		int u, v, w; cin >> u >> v >> w;
		to[u].emplace_back(v, w);
		to[v].emplace_back(u, w);
	}int timer = 0;
	vector<S>tmp(2 * n);
	vector<int>weight(n), in(n), out(n);
	auto dfs = [&](auto self, int v, int p = -1)->void {
		tmp[timer] = { weight[v], 1 };
		in[v] = timer;
		timer++;
		for (auto e : to[v]) {
			if (p == e.first)continue;
			weight[e.first] = e.second;
			self(self, e.first, v);
		}
		tmp[timer] = { -weight[v], -1 };
		out[v] = timer;
		timer++;
	};
	dfs(dfs, 0);
	lazy_segtree<S, op, e, F, mapping, composition, id> seg(tmp);
	int q; cin >> q;
	while (q--) {
		int t; cin >> t;
		if (1 == t) {
			int v, x; cin >> v >> x;
			seg.apply(in[v] + 1, out[v], x);
		}
		else {
			int v; cin >> v;
			auto ans = seg.prod(0, in[v] + 1);
			cout << ans.value << endl;
		}
	}
	return 0;
}
0