/tmp/solutions/build/vertex_add_subtree_sum-main.cpp:
1| |#include <common.h>
2| |prelude;
3| |
4| |namespace {
5| |
6| |constexpr int N = 5e5;
7| |
8| |int a[N];
9| |int p[N];
10| |int l[N];
11| |u64 b[N + 1];
12| |
13| |} // namespace
14| |
15| 1|int main() {
16| 1| rd rd;
17| 1| wt wt;
18| 1| int n = rd.uh();
19| 1| int q = rd.uh();
20| 1|#ifdef LOCAL
21| 1| std::memset(l, 0, 4 * n);
22| 1|#endif
23| 1.21k| for (int i = 0; i < n; ++i) a[i] = rd.uw();
^1.21k^1.21k
------------------
| Branch (23:19): [True: 99.92%, False: 0.08%]
------------------
24| 1.21k| for (int i = 1; i < n; ++i) p[i] = rd.uh();
^1.21k^1.21k
------------------
| Branch (24:19): [True: 99.92%, False: 0.08%]
------------------
25| 1.21k| for (int i = n - 1; i > 0; --i) l[p[i]] += (l[i] += 1);
^1.21k^1.21k
------------------
| Branch (25:23): [True: 99.92%, False: 0.08%]
------------------
26| 1| l[0] = p[0] = n;
27| 1.21k| for (int i = 1; i < n; ++i) {
^1.21k
------------------
| Branch (27:19): [True: 99.92%, False: 0.08%]
------------------
28| 1.21k| int j = p[i];
29| 1.21k| int li = l[i];
30| 1.21k| int lj = l[j];
31| 1.21k| l[i] = p[i] = lj;
32| 1.21k| l[j] -= li;
33| 1.21k| }
34| 1.21k| for (int i = 0; i < n; ++i) b[l[i]] = a[i];
^1.21k^1.21k
------------------
| Branch (34:19): [True: 99.92%, False: 0.08%]
------------------
35| 1.21k| for (int i = 1; i <= n; ++i) b[i] += b[i - 1];
^1.21k^1.21k
------------------
| Branch (35:19): [True: 99.92%, False: 0.08%]
------------------
36| 1.21k| for (int i = n; i >= 1; --i) b[i] -= b[i - (i & -i)];
^1.21k^1.21k
------------------
| Branch (36:19): [True: 99.92%, False: 0.08%]
------------------
37| 1.26k| while (q--) {
------------------
| Branch (37:10): [True: 99.92%, False: 0.08%]
------------------
38| 1.26k| let t = rd.u1();
39| 1.26k| if (t == 0) {
------------------
| Branch (39:9): [True: 51.07%, False: 48.93%]
------------------
40| 645| int k = l[rd.uh()];
41| 645| int x = rd.uw();
42| 4.28k| for (; k <= n; k += k & -k) b[k] += x;
^3.63k ^3.63k
------------------
| Branch (42:14): [True: 84.93%, False: 15.07%]
------------------
43| 645| }
44| 1.26k| if (t == 1) {
------------------
| Branch (44:9): [True: 48.93%, False: 51.07%]
------------------
45| 618| int x = rd.uh();
46| 618| int L = l[x] - 1;
47| 618| int R = p[x];
48| 618| u64 sum = 0;
49| 3.70k| for (; L > 0; L -= L & -L) sum -= b[L];
^3.08k ^3.08k
------------------
| Branch (49:14): [True: 83.32%, False: 16.68%]
------------------
50| 3.73k| for (; R > 0; R -= R & -R) sum += b[R];
^3.11k ^3.11k
------------------
| Branch (50:14): [True: 83.44%, False: 16.56%]
------------------
51| 618| wt.ud(sum);
52| 618| }
53| 1.26k| }
54| 1| return 0;
55| 1|}