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