/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|      5|void dfs(int u, int w) {
   23|      5|  p[u] = w;
   24|      5|  l[u] = ++id;
   25|      5|  c[id] += b[id] = a[u];
   26|     13|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^8
  ------------------
  |  Branch (26:25): [True: 61.54%, False: 38.46%]
  ------------------
   27|      8|    int v = edge[e].to;
   28|      8|    if (v != w) {
  ------------------
  |  Branch (28:9): [True: 50.00%, False: 50.00%]
  ------------------
   29|      4|      dfs(v, u);
   30|      4|    }
   31|      8|  }
   32|      5|  c[r[u] = id + 1] -= a[u];
   33|      5|}
   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|      6|  for (int i = 0; i < n; ++i) a[i] = rd.uw();
                                       ^5   ^5
  ------------------
  |  Branch (47:19): [True: 83.33%, False: 16.67%]
  ------------------
   48|      5|  for (int i = 1; i < n; ++i) {
                                       ^4
  ------------------
  |  Branch (48:19): [True: 80.00%, False: 20.00%]
  ------------------
   49|      4|    int u = rd.uh();
   50|      4|    int v = rd.uh();
   51|      4|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
   52|      4|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
   53|      4|  }
   54|      1|  dfs(0, -1);
   55|      1|  u64 sum = 0;
   56|      6|  for (int i = 1; i <= n; ++i) c[i] = sum += c[i];
                                        ^5   ^5
  ------------------
  |  Branch (56:19): [True: 83.33%, False: 16.67%]
  ------------------
   57|      6|  for (int i = n; i >= 1; --i) c[i] -= c[i - (i & -i)];
                                        ^5   ^5
  ------------------
  |  Branch (57:19): [True: 83.33%, False: 16.67%]
  ------------------
   58|      1|  int val[n + 1];
   59|      5|  for (int i = 1; i < n; ++i) val[l[i]] = l[p[i]];
                                       ^4   ^4
  ------------------
  |  Branch (59:19): [True: 80.00%, False: 20.00%]
  ------------------
   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|      7|  for (int min, i = 0; i < n; ++i) {
                                            ^6
  ------------------
  |  Branch (66:24): [True: 85.71%, False: 14.29%]
  ------------------
   67|      6|    int id = i & 63;
   68|      6|    int value = pre[i] = val[i];
   69|      6|    suf[i] = min = id ? std::min(min, value) : value;
                                      ^5                     ^1
  ------------------
  |  Branch (69:20): [True: 83.33%, False: 16.67%]
  ------------------
   70|      6|    if (id == 63) table[0][i / 64] = suf[i];
                                ^0
  ------------------
  |  Branch (70:9): [True: 0.00%, False: 100.00%]
  ------------------
   71|      6|  }
   72|      6|  for (int min, i = n - 2; i >= 0; --i) {
                                                 ^5
  ------------------
  |  Branch (72:28): [True: 83.33%, False: 16.67%]
  ------------------
   73|      5|    int id = ~i & 63;
   74|      5|    int value = pre[i];
   75|      5|    pre[i] = min = id ? std::min(min, value) : value;
                                                             ^0
  ------------------
  |  Branch (75:20): [True: 100.00%, False: 0.00%]
  ------------------
   76|      5|  }
   77|      1|  for (int i = 1; i < len; ++i) {
                                         ^0
  ------------------
  |  Branch (77:19): [True: 0.00%, False: 100.00%]
  ------------------
   78|      0|    for (int j = 0, k = 1 << (i - 1); k < m; ++j, ++k) {
  ------------------
  |  Branch (78:39): [True: 0.00%, False: 0.00%]
  ------------------
   79|      0|      table[i][j] = std::min(table[i - 1][j], table[i - 1][k]);
   80|      0|    }
   81|      0|  }
   82|      6|  while (q--) {
  ------------------
  |  Branch (82:10): [True: 83.33%, False: 16.67%]
  ------------------
   83|      5|    let t = rd.u1();
   84|      5|    if (t == 0) {
  ------------------
  |  Branch (84:9): [True: 20.00%, False: 80.00%]
  ------------------
   85|      1|      int k = rd.uh();
   86|      1|      int x = rd.uw();
   87|      1|      int u = l[k];
   88|      1|      int v = r[k];
   89|      1|      b[u] += x;
   90|      3|      for (; u <= n; u += u & -u) c[u] += x;
                                   ^2           ^2
  ------------------
  |  Branch (90:14): [True: 66.67%, False: 33.33%]
  ------------------
   91|      2|      for (; v <= n; v += v & -v) c[v] -= x;
                                   ^1           ^1
  ------------------
  |  Branch (91:14): [True: 50.00%, False: 50.00%]
  ------------------
   92|      1|    }
   93|      5|    if (t == 1) {
  ------------------
  |  Branch (93:9): [True: 80.00%, False: 20.00%]
  ------------------
   94|      4|      int u = l[rd.uh()];
   95|      4|      int v = l[rd.uh()];
   96|      4|      if (u == v) {
  ------------------
  |  Branch (96:11): [True: 0.00%, False: 100.00%]
  ------------------
   97|      0|        wt.ud(b[u]);
   98|      0|        continue;
   99|      0|      }
  100|      4|      int l = std::min(u, v) + 1;
  101|      4|      int r = std::max(u, v);
  102|      4|      int L = l / 64;
  103|      4|      int R = r / 64;
  104|      4|      int w;
  105|      4|      if (L < R - 1) {
  ------------------
  |  Branch (105:11): [True: 0.00%, False: 100.00%]
  ------------------
  106|      0|        int p = pre[l];
  107|      0|        int s = suf[r];
  108|      0|        w = std::min(p, s);
  109|      0|        int k = log(R - L - 1);
  110|      0|        int a = table[k][L + 1];
  111|      0|        int b = table[k][R - (1 << k)];
  112|      0|        int tmp = std::min(a, b);
  113|      0|        w = std::min(w, tmp);
  114|      4|      } else if (L == R - 1) {
  ------------------
  |  Branch (114:18): [True: 0.00%, False: 100.00%]
  ------------------
  115|      0|        int p = pre[l];
  116|      0|        int s = suf[r];
  117|      0|        w = std::min(p, s);
  118|      4|      } else {
  119|      4|        w = val[l];
  120|      9|        for (int i = l + 1; i <= r; ++i) w = std::min(w, val[i]);
                                                  ^5   ^5
  ------------------
  |  Branch (120:29): [True: 55.56%, False: 44.44%]
  ------------------
  121|      4|      }
  122|      4|      u64 sum = b[w];
  123|      4|      --l;
  124|      9|      for (; l; l -= l & -l) sum += c[l];
                              ^5           ^5
  ------------------
  |  Branch (124:14): [True: 55.56%, False: 44.44%]
  ------------------
  125|     11|      for (; r; r -= r & -r) sum += c[r];
                              ^7           ^7
  ------------------
  |  Branch (125:14): [True: 63.64%, False: 36.36%]
  ------------------
  126|      8|      for (; w; w -= w & -w) sum -= c[w] * 2;
                              ^4           ^4
  ------------------
  |  Branch (126:14): [True: 50.00%, False: 50.00%]
  ------------------
  127|      4|      wt.ud(sum);
  128|      4|    }
  129|      5|  }
  130|      1|  return 0;
  131|      1|}