/tmp/solutions/build/vertex_add_path_sum-slow.cpp:
    1|       |#include <common.h>
    2|       |#include <toy/bit.h>
    3|       |prelude;
    4|       |
    5|       |namespace {
    6|       |
    7|       |constexpr int N = 5e5;
    8|       |
    9|       |int head[N];
   10|       |struct {
   11|       |  int to;
   12|       |  int next;
   13|       |} edge[N * 2];
   14|       |int p[N];
   15|       |int l[N];
   16|       |int r[N];
   17|       |int a[N];
   18|       |u64 b[N + 1];
   19|       |u64 c[N + 2];
   20|       |int id;
   21|       |
   22|    693|void dfs(int u, int w) {
   23|    693|  p[u] = w;
   24|    693|  l[u] = ++id;
   25|    693|  c[id] += b[id] = a[u];
   26|  2.07k|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^1.38k
  ------------------
  |  Branch (26:25): [True: 66.63%, False: 33.37%]
  ------------------
   27|  1.38k|    int v = edge[e].to;
   28|  1.38k|    if (v != w) {
  ------------------
  |  Branch (28:9): [True: 50.00%, False: 50.00%]
  ------------------
   29|    692|      dfs(v, u);
   30|    692|    }
   31|  1.38k|  }
   32|    693|  c[r[u] = id + 1] -= a[u];
   33|    693|}
   34|       |
   35|       |} // namespace
   36|       |
   37|      1|int main() {
   38|      1|  rd rd;
   39|      1|  wt wt;
   40|      1|  int n = rd.uh();
   41|      1|  int q = rd.uh();
   42|      1|#ifdef LOCAL
   43|      1|  id = 0;
   44|      1|  std::memset(head, 0, 4 * n);
   45|      1|  std::memset(c, 0, 8 * n + 16);
   46|      1|#endif
   47|    694|  for (int i = 0; i < n; ++i) a[i] = rd.uw();
                                       ^693 ^693
  ------------------
  |  Branch (47:19): [True: 99.86%, False: 0.14%]
  ------------------
   48|    693|  for (int i = 1; i < n; ++i) {
                                       ^692
  ------------------
  |  Branch (48:19): [True: 99.86%, False: 0.14%]
  ------------------
   49|    692|    int u = rd.uh();
   50|    692|    int v = rd.uh();
   51|    692|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
   52|    692|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
   53|    692|  }
   54|      1|  dfs(0, -1);
   55|      1|  u64 sum = 0;
   56|    694|  for (int i = 1; i <= n; ++i) c[i] = sum += c[i];
                                        ^693 ^693
  ------------------
  |  Branch (56:19): [True: 99.86%, False: 0.14%]
  ------------------
   57|    694|  for (int i = n; i >= 1; --i) c[i] -= c[i - (i & -i)];
                                        ^693 ^693
  ------------------
  |  Branch (57:19): [True: 99.86%, False: 0.14%]
  ------------------
   58|      1|  int val[n + 1];
   59|    693|  for (int i = 1; i < n; ++i) val[l[i]] = l[p[i]];
                                       ^692 ^692
  ------------------
  |  Branch (59:19): [True: 99.86%, False: 0.14%]
  ------------------
   60|      1|  ++n;
   61|      1|  int m = n / 64 + 1;
   62|      1|  int len = log(m) + 1;
   63|      1|  int table[len][m];
   64|      1|  int suf[n];
   65|      1|  int pre[n];
   66|    695|  for (int min, i = 0; i < n; ++i) {
                                            ^694
  ------------------
  |  Branch (66:24): [True: 99.86%, False: 0.14%]
  ------------------
   67|    694|    int id = i & 63;
   68|    694|    int value = pre[i] = val[i];
   69|    694|    suf[i] = min = id ? std::min(min, value) : value;
                                      ^683                   ^11
  ------------------
  |  Branch (69:20): [True: 98.41%, False: 1.59%]
  ------------------
   70|    694|    if (id == 63) table[0][i / 64] = suf[i];
                                ^10
  ------------------
  |  Branch (70:9): [True: 1.44%, False: 98.56%]
  ------------------
   71|    694|  }
   72|    694|  for (int min, i = n - 2; i >= 0; --i) {
                                                 ^693
  ------------------
  |  Branch (72:28): [True: 99.86%, False: 0.14%]
  ------------------
   73|    693|    int id = ~i & 63;
   74|    693|    int value = pre[i];
   75|    693|    pre[i] = min = id ? std::min(min, value) : value;
                                      ^683                   ^10
  ------------------
  |  Branch (75:20): [True: 98.56%, False: 1.44%]
  ------------------
   76|    693|  }
   77|      4|  for (int i = 1; i < len; ++i) {
                                         ^3
  ------------------
  |  Branch (77:19): [True: 75.00%, False: 25.00%]
  ------------------
   78|     29|    for (int j = 0, k = 1 << (i - 1); k < m; ++j, ++k) {
                                                           ^26
  ------------------
  |  Branch (78:39): [True: 89.66%, False: 10.34%]
  ------------------
   79|     26|      table[i][j] = std::min(table[i - 1][j], table[i - 1][k]);
   80|     26|    }
   81|      3|  }
   82|    300|  while (q--) {
  ------------------
  |  Branch (82:10): [True: 99.67%, False: 0.33%]
  ------------------
   83|    299|    let t = rd.u1();
   84|    299|    if (t == 0) {
  ------------------
  |  Branch (84:9): [True: 54.85%, False: 45.15%]
  ------------------
   85|    164|      int k = rd.uh();
   86|    164|      int x = rd.uw();
   87|    164|      int u = l[k];
   88|    164|      int v = r[k];
   89|    164|      b[u] += x;
   90|    985|      for (; u <= n; u += u & -u) c[u] += x;
                                   ^821         ^821
  ------------------
  |  Branch (90:14): [True: 83.35%, False: 16.65%]
  ------------------
   91|    984|      for (; v <= n; v += v & -v) c[v] -= x;
                                   ^820         ^820
  ------------------
  |  Branch (91:14): [True: 83.33%, False: 16.67%]
  ------------------
   92|    164|    }
   93|    299|    if (t == 1) {
  ------------------
  |  Branch (93:9): [True: 45.15%, False: 54.85%]
  ------------------
   94|    135|      int u = l[rd.uh()];
   95|    135|      int v = l[rd.uh()];
   96|    135|      if (u == v) {
  ------------------
  |  Branch (96:11): [True: 0.74%, False: 99.26%]
  ------------------
   97|      1|        wt.ud(b[u]);
   98|      1|        continue;
   99|      1|      }
  100|    134|      int l = std::min(u, v) + 1;
  101|    134|      int r = std::max(u, v);
  102|    134|      int L = l / 64;
  103|    134|      int R = r / 64;
  104|    134|      int w;
  105|    134|      if (L < R - 1) {
  ------------------
  |  Branch (105:11): [True: 76.12%, False: 23.88%]
  ------------------
  106|    102|        int p = pre[l];
  107|    102|        int s = suf[r];
  108|    102|        w = std::min(p, s);
  109|    102|        int k = log(R - L - 1);
  110|    102|        int a = table[k][L + 1];
  111|    102|        int b = table[k][R - (1 << k)];
  112|    102|        int tmp = std::min(a, b);
  113|    102|        w = std::min(w, tmp);
  114|    102|      } else if (L == R - 1) {
                           ^32 ^32
  ------------------
  |  Branch (114:18): [True: 59.38%, False: 40.62%]
  ------------------
  115|     19|        int p = pre[l];
  116|     19|        int s = suf[r];
  117|     19|        w = std::min(p, s);
  118|     19|      } else {
  119|     13|        w = val[l];
  120|    209|        for (int i = l + 1; i <= r; ++i) w = std::min(w, val[i]);
                                                  ^196 ^196
  ------------------
  |  Branch (120:29): [True: 93.78%, False: 6.22%]
  ------------------
  121|     13|      }
  122|    134|      u64 sum = b[w];
  123|    134|      --l;
  124|    678|      for (; l; l -= l & -l) sum += c[l];
                              ^544         ^544
  ------------------
  |  Branch (124:14): [True: 80.24%, False: 19.76%]
  ------------------
  125|    795|      for (; r; r -= r & -r) sum += c[r];
                              ^661         ^661
  ------------------
  |  Branch (125:14): [True: 83.14%, False: 16.86%]
  ------------------
  126|    682|      for (; w; w -= w & -w) sum -= c[w] * 2;
                              ^548         ^548
  ------------------
  |  Branch (126:14): [True: 80.35%, False: 19.65%]
  ------------------
  127|    134|      wt.ud(sum);
  128|    134|    }
  129|    299|  }
  130|      1|  return 0;
  131|      1|}