/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|    533|  for (int i = 0; i < n; ++i) a[i] = rd.uw();
                                       ^532 ^532
  ------------------
  |  Branch (32:19): [True: 99.81%, False: 0.19%]
  ------------------
   33|    532|  for (int i = 1; i < n; ++i) {
                                       ^531
  ------------------
  |  Branch (33:19): [True: 99.81%, False: 0.19%]
  ------------------
   34|    531|    int u = rd.uh();
   35|    531|    int v = rd.uh();
   36|    531|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
   37|    531|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
   38|    531|  }
   39|      1|  p[0] = -1, l[0] = 1, b[1] = c[1] = a[0];
   40|  1.59k|  for (int u = 0, i = 1; u >= 0;) {
  ------------------
  |  Branch (40:26): [True: 99.94%, False: 0.06%]
  ------------------
   41|  1.59k|    if (int e = head[u]; e) {
  ------------------
  |  Branch (41:26): [True: 66.62%, False: 33.38%]
  ------------------
   42|  1.06k|      def[v, x] = edge[e];
   43|  1.06k|      head[u] = x;
   44|  1.06k|      if (v == p[u]) continue;
                                   ^531
  ------------------
  |  Branch (44:11): [True: 50.00%, False: 50.00%]
  ------------------
   45|    531|      p[v] = u;
   46|    531|      l[v] = ++i;
   47|    531|      c[i] += b[i] = a[v];
   48|    531|      u = v;
   49|    532|    } else {
   50|    532|      c[r[u] = i + 1] -= a[u];
   51|    532|      u = p[u];
   52|    532|    }
   53|  1.59k|  }
   54|      1|  u64 sum = 0;
   55|    533|  for (int i = 1; i <= n; ++i) c[i] = sum += c[i];
                                        ^532 ^532
  ------------------
  |  Branch (55:19): [True: 99.81%, False: 0.19%]
  ------------------
   56|    533|  for (int i = n; i >= 1; --i) c[i] -= c[i - (i & -i)];
                                        ^532 ^532
  ------------------
  |  Branch (56:19): [True: 99.81%, False: 0.19%]
  ------------------
   57|      1|  int val[n + 1];
   58|    532|  for (int i = 1; i < n; ++i) val[l[i]] = l[p[i]];
                                       ^531 ^531
  ------------------
  |  Branch (58:19): [True: 99.81%, False: 0.19%]
  ------------------
   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|    534|  for (int min, i = 0; i < n; ++i) {
                                            ^533
  ------------------
  |  Branch (65:24): [True: 99.81%, False: 0.19%]
  ------------------
   66|    533|    int id = i & 63;
   67|    533|    int value = pre[i] = val[i];
   68|    533|    suf[i] = min = id ? std::min(min, value) : value;
                                      ^524                   ^9
  ------------------
  |  Branch (68:20): [True: 98.31%, False: 1.69%]
  ------------------
   69|    533|    if (id == 63) table[0][i / 64] = suf[i];
                                ^8
  ------------------
  |  Branch (69:9): [True: 1.50%, False: 98.50%]
  ------------------
   70|    533|  }
   71|    533|  for (int min, i = n - 2; i >= 0; --i) {
                                                 ^532
  ------------------
  |  Branch (71:28): [True: 99.81%, False: 0.19%]
  ------------------
   72|    532|    int id = ~i & 63;
   73|    532|    int value = pre[i];
   74|    532|    pre[i] = min = id ? std::min(min, value) : value;
                                      ^524                   ^8
  ------------------
  |  Branch (74:20): [True: 98.50%, False: 1.50%]
  ------------------
   75|    532|  }
   76|      4|  for (int i = 1; i < len; ++i) {
                                         ^3
  ------------------
  |  Branch (76:19): [True: 75.00%, False: 25.00%]
  ------------------
   77|     23|    for (int j = 0, k = 1 << (i - 1); k < m; ++j, ++k) {
                                                           ^20
  ------------------
  |  Branch (77:39): [True: 86.96%, False: 13.04%]
  ------------------
   78|     20|      table[i][j] = std::min(table[i - 1][j], table[i - 1][k]);
   79|     20|    }
   80|      3|  }
   81|    814|  while (q--) {
  ------------------
  |  Branch (81:10): [True: 99.88%, False: 0.12%]
  ------------------
   82|    813|    let t = rd.u1();
   83|    813|    if (t == 0) {
  ------------------
  |  Branch (83:9): [True: 49.94%, False: 50.06%]
  ------------------
   84|    406|      int k = rd.uh();
   85|    406|      int x = rd.uw();
   86|    406|      int u = l[k];
   87|    406|      int v = r[k];
   88|    406|      b[u] += x;
   89|  2.56k|      for (; u <= n; u += u & -u) c[u] += x;
                                   ^2.16k       ^2.16k
  ------------------
  |  Branch (89:14): [True: 84.18%, False: 15.82%]
  ------------------
   90|  2.47k|      for (; v <= n; v += v & -v) c[v] -= x;
                                   ^2.07k       ^2.07k
  ------------------
  |  Branch (90:14): [True: 83.62%, False: 16.38%]
  ------------------
   91|    406|    }
   92|    813|    if (t == 1) {
  ------------------
  |  Branch (92:9): [True: 50.06%, False: 49.94%]
  ------------------
   93|    407|      int u = l[rd.uh()];
   94|    407|      int v = l[rd.uh()];
   95|    407|      if (u == v) {
  ------------------
  |  Branch (95:11): [True: 0.49%, False: 99.51%]
  ------------------
   96|      2|        wt.ud(b[u]);
   97|      2|        continue;
   98|      2|      }
   99|    405|      int l = std::min(u, v) + 1;
  100|    405|      int r = std::max(u, v);
  101|    405|      int L = l / 64;
  102|    405|      int R = r / 64;
  103|    405|      int w;
  104|    405|      if (L < R - 1) {
  ------------------
  |  Branch (104:11): [True: 65.93%, False: 34.07%]
  ------------------
  105|    267|        int p = pre[l];
  106|    267|        int s = suf[r];
  107|    267|        w = std::min(p, s);
  108|    267|        int k = log(R - L - 1);
  109|    267|        int a = table[k][L + 1];
  110|    267|        int b = table[k][R - (1 << k)];
  111|    267|        int tmp = std::min(a, b);
  112|    267|        w = std::min(w, tmp);
  113|    267|      } else if (L == R - 1) {
                           ^138^138
  ------------------
  |  Branch (113:18): [True: 65.22%, False: 34.78%]
  ------------------
  114|     90|        int p = pre[l];
  115|     90|        int s = suf[r];
  116|     90|        w = std::min(p, s);
  117|     90|      } else {
  118|     48|        w = val[l];
  119|  1.01k|        for (int i = l + 1; i <= r; ++i) w = std::min(w, val[i]);
                                                  ^970 ^970
  ------------------
  |  Branch (119:29): [True: 95.28%, False: 4.72%]
  ------------------
  120|     48|      }
  121|    405|      u64 sum = b[w];
  122|    405|      --l;
  123|  2.08k|      for (; l; l -= l & -l) sum += c[l];
                              ^1.68k       ^1.68k
  ------------------
  |  Branch (123:14): [True: 80.59%, False: 19.41%]
  ------------------
  124|  2.36k|      for (; r; r -= r & -r) sum += c[r];
                              ^1.95k       ^1.95k
  ------------------
  |  Branch (124:14): [True: 82.86%, False: 17.14%]
  ------------------
  125|  2.16k|      for (; w; w -= w & -w) sum -= c[w] * 2;
                              ^1.75k       ^1.75k
  ------------------
  |  Branch (125:14): [True: 81.28%, False: 18.72%]
  ------------------
  126|    405|      wt.ud(sum);
  127|    405|    }
  128|    813|  }
  129|      1|  return 0;
  130|      1|}