/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|     89|  for (int i = 0; i < n; ++i) a[i] = rd.uw();
                                       ^88  ^88
  ------------------
  |  Branch (32:19): [True: 98.88%, False: 1.12%]
  ------------------
   33|     88|  for (int i = 1; i < n; ++i) {
                                       ^87
  ------------------
  |  Branch (33:19): [True: 98.86%, False: 1.14%]
  ------------------
   34|     87|    int u = rd.uh();
   35|     87|    int v = rd.uh();
   36|     87|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
   37|     87|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
   38|     87|  }
   39|      1|  p[0] = -1, l[0] = 1, b[1] = c[1] = a[0];
   40|    263|  for (int u = 0, i = 1; u >= 0;) {
  ------------------
  |  Branch (40:26): [True: 99.62%, False: 0.38%]
  ------------------
   41|    262|    if (int e = head[u]; e) {
  ------------------
  |  Branch (41:26): [True: 66.41%, False: 33.59%]
  ------------------
   42|    174|      def[v, x] = edge[e];
   43|    174|      head[u] = x;
   44|    174|      if (v == p[u]) continue;
                                   ^87
  ------------------
  |  Branch (44:11): [True: 50.00%, False: 50.00%]
  ------------------
   45|     87|      p[v] = u;
   46|     87|      l[v] = ++i;
   47|     87|      c[i] += b[i] = a[v];
   48|     87|      u = v;
   49|     88|    } else {
   50|     88|      c[r[u] = i + 1] -= a[u];
   51|     88|      u = p[u];
   52|     88|    }
   53|    262|  }
   54|      1|  u64 sum = 0;
   55|     89|  for (int i = 1; i <= n; ++i) c[i] = sum += c[i];
                                        ^88  ^88
  ------------------
  |  Branch (55:19): [True: 98.88%, False: 1.12%]
  ------------------
   56|     89|  for (int i = n; i >= 1; --i) c[i] -= c[i - (i & -i)];
                                        ^88  ^88
  ------------------
  |  Branch (56:19): [True: 98.88%, False: 1.12%]
  ------------------
   57|      1|  int val[n + 1];
   58|     88|  for (int i = 1; i < n; ++i) val[l[i]] = l[p[i]];
                                       ^87  ^87
  ------------------
  |  Branch (58:19): [True: 98.86%, False: 1.14%]
  ------------------
   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|     90|  for (int min, i = 0; i < n; ++i) {
                                            ^89
  ------------------
  |  Branch (65:24): [True: 98.89%, False: 1.11%]
  ------------------
   66|     89|    int id = i & 63;
   67|     89|    int value = pre[i] = val[i];
   68|     89|    suf[i] = min = id ? std::min(min, value) : value;
                                      ^87                    ^2
  ------------------
  |  Branch (68:20): [True: 97.75%, False: 2.25%]
  ------------------
   69|     89|    if (id == 63) table[0][i / 64] = suf[i];
                                ^1
  ------------------
  |  Branch (69:9): [True: 1.12%, False: 98.88%]
  ------------------
   70|     89|  }
   71|     89|  for (int min, i = n - 2; i >= 0; --i) {
                                                 ^88
  ------------------
  |  Branch (71:28): [True: 98.88%, False: 1.12%]
  ------------------
   72|     88|    int id = ~i & 63;
   73|     88|    int value = pre[i];
   74|     88|    pre[i] = min = id ? std::min(min, value) : value;
                                      ^87                    ^1
  ------------------
  |  Branch (74:20): [True: 98.86%, False: 1.14%]
  ------------------
   75|     88|  }
   76|      2|  for (int i = 1; i < len; ++i) {
                                         ^1
  ------------------
  |  Branch (76:19): [True: 50.00%, False: 50.00%]
  ------------------
   77|      2|    for (int j = 0, k = 1 << (i - 1); k < m; ++j, ++k) {
                                                           ^1
  ------------------
  |  Branch (77:39): [True: 50.00%, False: 50.00%]
  ------------------
   78|      1|      table[i][j] = std::min(table[i - 1][j], table[i - 1][k]);
   79|      1|    }
   80|      1|  }
   81|    396|  while (q--) {
  ------------------
  |  Branch (81:10): [True: 99.75%, False: 0.25%]
  ------------------
   82|    395|    let t = rd.u1();
   83|    395|    if (t == 0) {
  ------------------
  |  Branch (83:9): [True: 51.90%, False: 48.10%]
  ------------------
   84|    205|      int k = rd.uh();
   85|    205|      int x = rd.uw();
   86|    205|      int u = l[k];
   87|    205|      int v = r[k];
   88|    205|      b[u] += x;
   89|    952|      for (; u <= n; u += u & -u) c[u] += x;
                                   ^747         ^747
  ------------------
  |  Branch (89:14): [True: 78.47%, False: 21.53%]
  ------------------
   90|    908|      for (; v <= n; v += v & -v) c[v] -= x;
                                   ^703         ^703
  ------------------
  |  Branch (90:14): [True: 77.42%, False: 22.58%]
  ------------------
   91|    205|    }
   92|    395|    if (t == 1) {
  ------------------
  |  Branch (92:9): [True: 48.10%, False: 51.90%]
  ------------------
   93|    190|      int u = l[rd.uh()];
   94|    190|      int v = l[rd.uh()];
   95|    190|      if (u == v) {
  ------------------
  |  Branch (95:11): [True: 0.53%, False: 99.47%]
  ------------------
   96|      1|        wt.ud(b[u]);
   97|      1|        continue;
   98|      1|      }
   99|    189|      int l = std::min(u, v) + 1;
  100|    189|      int r = std::max(u, v);
  101|    189|      int L = l / 64;
  102|    189|      int R = r / 64;
  103|    189|      int w;
  104|    189|      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|    189|      } else if (L == R - 1) {
  ------------------
  |  Branch (113:18): [True: 47.09%, False: 52.91%]
  ------------------
  114|     89|        int p = pre[l];
  115|     89|        int s = suf[r];
  116|     89|        w = std::min(p, s);
  117|    100|      } else {
  118|    100|        w = val[l];
  119|  1.84k|        for (int i = l + 1; i <= r; ++i) w = std::min(w, val[i]);
                                                  ^1.74k^1.74k
  ------------------
  |  Branch (119:29): [True: 94.57%, False: 5.43%]
  ------------------
  120|    100|      }
  121|    189|      u64 sum = b[w];
  122|    189|      --l;
  123|    710|      for (; l; l -= l & -l) sum += c[l];
                              ^521         ^521
  ------------------
  |  Branch (123:14): [True: 73.38%, False: 26.62%]
  ------------------
  124|    809|      for (; r; r -= r & -r) sum += c[r];
                              ^620         ^620
  ------------------
  |  Branch (124:14): [True: 76.64%, False: 23.36%]
  ------------------
  125|    709|      for (; w; w -= w & -w) sum -= c[w] * 2;
                              ^520         ^520
  ------------------
  |  Branch (125:14): [True: 73.34%, False: 26.66%]
  ------------------
  126|    189|      wt.ud(sum);
  127|    189|    }
  128|    395|  }
  129|      1|  return 0;
  130|      1|}