Skip to content

Commit 73fb341

Browse files
committed
fix
1 parent a2ba6d0 commit 73fb341

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree.test.cpp renamed to tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_edges.test.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,23 @@ int main() {
1616
adj[par].push_back(i);
1717
adj[i].push_back(par);
1818
}
19-
HLD<0> hld_nodes(adj);
20-
HLD<1> hld_edges(adj);
19+
HLD<1> hld(adj);
2120
BIT bit(n);
22-
for (int i = 0; i < n; i++)
23-
bit.update(hld_nodes.tin[i], a[i]);
21+
for (int i = 0; i < n; i++) bit.update(hld.tin[i], a[i]);
2422
while (q--) {
2523
int type;
2624
cin >> type;
2725
if (type == 0) {
2826
int v, x;
2927
cin >> v >> x;
30-
bit.update(hld_nodes.tin[v], x);
28+
bit.update(hld.tin[v], x);
3129
a[v] += x;
3230
} else {
3331
int v;
3432
cin >> v;
35-
auto [l, r] = hld_nodes.subtree(v);
33+
auto [l, r] = hld.subtree(v);
3634
ll res = bit.query(l, r);
37-
auto [l_edges, r_edges] = hld_edges.subtree(v);
38-
assert(res == bit.query(l_edges, r_edges) + a[v]);
39-
cout << res << '\n';
35+
cout << bit.query(l, r) + a[v] << '\n';
4036
}
4137
}
4238
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#define PROBLEM \
2+
"https://judge.yosupo.jp/problem/vertex_add_subtree_sum"
3+
#include "../template.hpp"
4+
#include "../../../library/trees/hld.hpp"
5+
#include "../../../library/data_structures/bit.hpp"
6+
int main() {
7+
cin.tie(0)->sync_with_stdio(0);
8+
int n, q;
9+
cin >> n >> q;
10+
vector<ll> a(n);
11+
for (int i = 0; i < n; i++) cin >> a[i];
12+
vector<vector<int>> adj(n);
13+
for (int i = 1; i < n; i++) {
14+
int par;
15+
cin >> par;
16+
adj[par].push_back(i);
17+
adj[i].push_back(par);
18+
}
19+
HLD<0> hld(adj);
20+
BIT bit(n);
21+
for (int i = 0; i < n; i++) bit.update(hld.tin[i], a[i]);
22+
while (q--) {
23+
int type;
24+
cin >> type;
25+
if (type == 0) {
26+
int v, x;
27+
cin >> v >> x;
28+
bit.update(hld.tin[v], x);
29+
} else {
30+
int v;
31+
cin >> v;
32+
auto [l, r] = hld.subtree(v);
33+
cout << bit.query(l, r) << '\n';
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)