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