/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|    199|  for (int i = 0; i < n; ++i) a[i] = rd.uw();
                                       ^198 ^198
  ------------------
  |  Branch (32:19): [True: 99.50%, False: 0.50%]
  ------------------
   33|    198|  for (int i = 1; i < n; ++i) {
                                       ^197
  ------------------
  |  Branch (33:19): [True: 99.49%, False: 0.51%]
  ------------------
   34|    197|    int u = rd.uh();
   35|    197|    int v = rd.uh();
   36|    197|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
   37|    197|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
   38|    197|  }
   39|      1|  p[0] = -1, l[0] = 1, b[1] = c[1] = a[0];
   40|    593|  for (int u = 0, i = 1; u >= 0;) {
  ------------------
  |  Branch (40:26): [True: 99.83%, False: 0.17%]
  ------------------
   41|    592|    if (int e = head[u]; e) {
  ------------------
  |  Branch (41:26): [True: 66.55%, False: 33.45%]
  ------------------
   42|    394|      def[v, x] = edge[e];
   43|    394|      head[u] = x;
   44|    394|      if (v == p[u]) continue;
                                   ^197
  ------------------
  |  Branch (44:11): [True: 50.00%, False: 50.00%]
  ------------------
   45|    197|      p[v] = u;
   46|    197|      l[v] = ++i;
   47|    197|      c[i] += b[i] = a[v];
   48|    197|      u = v;
   49|    198|    } else {
   50|    198|      c[r[u] = i + 1] -= a[u];
   51|    198|      u = p[u];
   52|    198|    }
   53|    592|  }
   54|      1|  u64 sum = 0;
   55|    199|  for (int i = 1; i <= n; ++i) c[i] = sum += c[i];
                                        ^198 ^198
  ------------------
  |  Branch (55:19): [True: 99.50%, False: 0.50%]
  ------------------
   56|    199|  for (int i = n; i >= 1; --i) c[i] -= c[i - (i & -i)];
                                        ^198 ^198
  ------------------
  |  Branch (56:19): [True: 99.50%, False: 0.50%]
  ------------------
   57|      1|  int val[n + 1];
   58|    198|  for (int i = 1; i < n; ++i) val[l[i]] = l[p[i]];
                                       ^197 ^197
  ------------------
  |  Branch (58:19): [True: 99.49%, False: 0.51%]
  ------------------
   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|    200|  for (int min, i = 0; i < n; ++i) {
                                            ^199
  ------------------
  |  Branch (65:24): [True: 99.50%, False: 0.50%]
  ------------------
   66|    199|    int id = i & 63;
   67|    199|    int value = pre[i] = val[i];
   68|    199|    suf[i] = min = id ? std::min(min, value) : value;
                                      ^195                   ^4
  ------------------
  |  Branch (68:20): [True: 97.99%, False: 2.01%]
  ------------------
   69|    199|    if (id == 63) table[0][i / 64] = suf[i];
                                ^3
  ------------------
  |  Branch (69:9): [True: 1.51%, False: 98.49%]
  ------------------
   70|    199|  }
   71|    199|  for (int min, i = n - 2; i >= 0; --i) {
                                                 ^198
  ------------------
  |  Branch (71:28): [True: 99.50%, False: 0.50%]
  ------------------
   72|    198|    int id = ~i & 63;
   73|    198|    int value = pre[i];
   74|    198|    pre[i] = min = id ? std::min(min, value) : value;
                                      ^195                   ^3
  ------------------
  |  Branch (74:20): [True: 98.48%, False: 1.52%]
  ------------------
   75|    198|  }
   76|      3|  for (int i = 1; i < len; ++i) {
                                         ^2
  ------------------
  |  Branch (76:19): [True: 66.67%, False: 33.33%]
  ------------------
   77|      7|    for (int j = 0, k = 1 << (i - 1); k < m; ++j, ++k) {
                                                           ^5
  ------------------
  |  Branch (77:39): [True: 71.43%, False: 28.57%]
  ------------------
   78|      5|      table[i][j] = std::min(table[i - 1][j], table[i - 1][k]);
   79|      5|    }
   80|      2|  }
   81|    236|  while (q--) {
  ------------------
  |  Branch (81:10): [True: 99.58%, False: 0.42%]
  ------------------
   82|    235|    let t = rd.u1();
   83|    235|    if (t == 0) {
  ------------------
  |  Branch (83:9): [True: 51.06%, False: 48.94%]
  ------------------
   84|    120|      int k = rd.uh();
   85|    120|      int x = rd.uw();
   86|    120|      int u = l[k];
   87|    120|      int v = r[k];
   88|    120|      b[u] += x;
   89|    616|      for (; u <= n; u += u & -u) c[u] += x;
                                   ^496         ^496
  ------------------
  |  Branch (89:14): [True: 80.52%, False: 19.48%]
  ------------------
   90|    600|      for (; v <= n; v += v & -v) c[v] -= x;
                                   ^480         ^480
  ------------------
  |  Branch (90:14): [True: 80.00%, False: 20.00%]
  ------------------
   91|    120|    }
   92|    235|    if (t == 1) {
  ------------------
  |  Branch (92:9): [True: 48.94%, False: 51.06%]
  ------------------
   93|    115|      int u = l[rd.uh()];
   94|    115|      int v = l[rd.uh()];
   95|    115|      if (u == v) {
  ------------------
  |  Branch (95:11): [True: 1.74%, False: 98.26%]
  ------------------
   96|      2|        wt.ud(b[u]);
   97|      2|        continue;
   98|      2|      }
   99|    113|      int l = std::min(u, v) + 1;
  100|    113|      int r = std::max(u, v);
  101|    113|      int L = l / 64;
  102|    113|      int R = r / 64;
  103|    113|      int w;
  104|    113|      if (L < R - 1) {
  ------------------
  |  Branch (104:11): [True: 15.04%, False: 84.96%]
  ------------------
  105|     17|        int p = pre[l];
  106|     17|        int s = suf[r];
  107|     17|        w = std::min(p, s);
  108|     17|        int k = log(R - L - 1);
  109|     17|        int a = table[k][L + 1];
  110|     17|        int b = table[k][R - (1 << k)];
  111|     17|        int tmp = std::min(a, b);
  112|     17|        w = std::min(w, tmp);
  113|     96|      } else if (L == R - 1) {
  ------------------
  |  Branch (113:18): [True: 48.96%, False: 51.04%]
  ------------------
  114|     47|        int p = pre[l];
  115|     47|        int s = suf[r];
  116|     47|        w = std::min(p, s);
  117|     49|      } else {
  118|     49|        w = val[l];
  119|  1.10k|        for (int i = l + 1; i <= r; ++i) w = std::min(w, val[i]);
                                                  ^1.05k^1.05k
  ------------------
  |  Branch (119:29): [True: 95.58%, False: 4.42%]
  ------------------
  120|     49|      }
  121|    113|      u64 sum = b[w];
  122|    113|      --l;
  123|    480|      for (; l; l -= l & -l) sum += c[l];
                              ^367         ^367
  ------------------
  |  Branch (123:14): [True: 76.46%, False: 23.54%]
  ------------------
  124|    590|      for (; r; r -= r & -r) sum += c[r];
                              ^477         ^477
  ------------------
  |  Branch (124:14): [True: 80.85%, False: 19.15%]
  ------------------
  125|    404|      for (; w; w -= w & -w) sum -= c[w] * 2;
                              ^291         ^291
  ------------------
  |  Branch (125:14): [True: 72.03%, False: 27.97%]
  ------------------
  126|    113|      wt.ud(sum);
  127|    113|    }
  128|    235|  }
  129|      1|  return 0;
  130|      1|}