/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|     19|int main() {
   24|     19|  rd rd;
   25|     19|  wt wt;
   26|     19|  int n = rd.uh();
   27|     19|  int q = rd.uh();
   28|     19|#ifdef LOCAL
   29|     19|  std::memset(head, 0, 4 * n);
   30|     19|  std::memset(c, 0, 8 * n + 16);
   31|     19|#endif
   32|  5.61M|  for (int i = 0; i < n; ++i) a[i] = rd.uw();
                                       ^5.61M^5.61M
  ------------------
  |  Branch (32:19): [True: 100.00%, False: 0.00%]
  ------------------
   33|  5.61M|  for (int i = 1; i < n; ++i) {
                                       ^5.61M
  ------------------
  |  Branch (33:19): [True: 100.00%, False: 0.00%]
  ------------------
   34|  5.61M|    int u = rd.uh();
   35|  5.61M|    int v = rd.uh();
   36|  5.61M|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
   37|  5.61M|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
   38|  5.61M|  }
   39|     19|  p[0] = -1, l[0] = 1, b[1] = c[1] = a[0];
   40|  16.8M|  for (int u = 0, i = 1; u >= 0;) {
  ------------------
  |  Branch (40:26): [True: 100.00%, False: 0.00%]
  ------------------
   41|  16.8M|    if (int e = head[u]; e) {
  ------------------
  |  Branch (41:26): [True: 66.67%, False: 33.33%]
  ------------------
   42|  11.2M|      def[v, x] = edge[e];
   43|  11.2M|      head[u] = x;
   44|  11.2M|      if (v == p[u]) continue;
                                   ^5.61M
  ------------------
  |  Branch (44:11): [True: 50.00%, False: 50.00%]
  ------------------
   45|  5.61M|      p[v] = u;
   46|  5.61M|      l[v] = ++i;
   47|  5.61M|      c[i] += b[i] = a[v];
   48|  5.61M|      u = v;
   49|  5.61M|    } else {
   50|  5.61M|      c[r[u] = i + 1] -= a[u];
   51|  5.61M|      u = p[u];
   52|  5.61M|    }
   53|  16.8M|  }
   54|     19|  u64 sum = 0;
   55|  5.61M|  for (int i = 1; i <= n; ++i) c[i] = sum += c[i];
                                        ^5.61M^5.61M
  ------------------
  |  Branch (55:19): [True: 100.00%, False: 0.00%]
  ------------------
   56|  5.61M|  for (int i = n; i >= 1; --i) c[i] -= c[i - (i & -i)];
                                        ^5.61M^5.61M
  ------------------
  |  Branch (56:19): [True: 100.00%, False: 0.00%]
  ------------------
   57|     19|  int val[n + 1];
   58|  5.61M|  for (int i = 1; i < n; ++i) val[l[i]] = l[p[i]];
                                       ^5.61M^5.61M
  ------------------
  |  Branch (58:19): [True: 100.00%, False: 0.00%]
  ------------------
   59|     19|  ++n;
   60|     19|  int m = n / 64 + 1;
   61|     19|  int len = log(m) + 1;
   62|     19|  int table[len][m];
   63|     19|  int suf[n];
   64|     19|  int pre[n];
   65|  5.61M|  for (int min, i = 0; i < n; ++i) {
                                            ^5.61M
  ------------------
  |  Branch (65:24): [True: 100.00%, False: 0.00%]
  ------------------
   66|  5.61M|    int id = i & 63;
   67|  5.61M|    int value = pre[i] = val[i];
   68|  5.61M|    suf[i] = min = id ? std::min(min, value) : value;
                                      ^5.52M                 ^87.7k
  ------------------
  |  Branch (68:20): [True: 98.44%, False: 1.56%]
  ------------------
   69|  5.61M|    if (id == 63) table[0][i / 64] = suf[i];
                                ^87.7k
  ------------------
  |  Branch (69:9): [True: 1.56%, False: 98.44%]
  ------------------
   70|  5.61M|  }
   71|  5.61M|  for (int min, i = n - 2; i >= 0; --i) {
                                                 ^5.61M
  ------------------
  |  Branch (71:28): [True: 100.00%, False: 0.00%]
  ------------------
   72|  5.61M|    int id = ~i & 63;
   73|  5.61M|    int value = pre[i];
   74|  5.61M|    pre[i] = min = id ? std::min(min, value) : value;
                                      ^5.52M                 ^87.7k
  ------------------
  |  Branch (74:20): [True: 98.44%, False: 1.56%]
  ------------------
   75|  5.61M|  }
   76|    183|  for (int i = 1; i < len; ++i) {
                                         ^164
  ------------------
  |  Branch (76:19): [True: 89.62%, False: 10.38%]
  ------------------
   77|  1.00M|    for (int j = 0, k = 1 << (i - 1); k < m; ++j, ++k) {
                                                           ^1.00M
  ------------------
  |  Branch (77:39): [True: 99.98%, False: 0.02%]
  ------------------
   78|  1.00M|      table[i][j] = std::min(table[i - 1][j], table[i - 1][k]);
   79|  1.00M|    }
   80|    164|  }
   81|  5.33M|  while (q--) {
  ------------------
  |  Branch (81:10): [True: 100.00%, False: 0.00%]
  ------------------
   82|  5.33M|    let t = rd.u1();
   83|  5.33M|    if (t == 0) {
  ------------------
  |  Branch (83:9): [True: 45.25%, False: 54.75%]
  ------------------
   84|  2.41M|      int k = rd.uh();
   85|  2.41M|      int x = rd.uw();
   86|  2.41M|      int u = l[k];
   87|  2.41M|      int v = r[k];
   88|  2.41M|      b[u] += x;
   89|  25.3M|      for (; u <= n; u += u & -u) c[u] += x;
                                   ^22.9M       ^22.9M
  ------------------
  |  Branch (89:14): [True: 90.47%, False: 9.53%]
  ------------------
   90|  21.1M|      for (; v <= n; v += v & -v) c[v] -= x;
                                   ^18.7M       ^18.7M
  ------------------
  |  Branch (90:14): [True: 88.58%, False: 11.42%]
  ------------------
   91|  2.41M|    }
   92|  5.33M|    if (t == 1) {
  ------------------
  |  Branch (92:9): [True: 54.75%, False: 45.25%]
  ------------------
   93|  2.92M|      int u = l[rd.uh()];
   94|  2.92M|      int v = l[rd.uh()];
   95|  2.92M|      if (u == v) {
  ------------------
  |  Branch (95:11): [True: 0.00%, False: 100.00%]
  ------------------
   96|     12|        wt.ud(b[u]);
   97|     12|        continue;
   98|     12|      }
   99|  2.92M|      int l = std::min(u, v) + 1;
  100|  2.92M|      int r = std::max(u, v);
  101|  2.92M|      int L = l / 64;
  102|  2.92M|      int R = r / 64;
  103|  2.92M|      int w;
  104|  2.92M|      if (L < R - 1) {
  ------------------
  |  Branch (104:11): [True: 99.93%, False: 0.07%]
  ------------------
  105|  2.91M|        int p = pre[l];
  106|  2.91M|        int s = suf[r];
  107|  2.91M|        w = std::min(p, s);
  108|  2.91M|        int k = log(R - L - 1);
  109|  2.91M|        int a = table[k][L + 1];
  110|  2.91M|        int b = table[k][R - (1 << k)];
  111|  2.91M|        int tmp = std::min(a, b);
  112|  2.91M|        w = std::min(w, tmp);
  113|  2.91M|      } else if (L == R - 1) {
                           ^2.16k^2.16k
  ------------------
  |  Branch (113:18): [True: 61.08%, False: 38.92%]
  ------------------
  114|  1.32k|        int p = pre[l];
  115|  1.32k|        int s = suf[r];
  116|  1.32k|        w = std::min(p, s);
  117|  1.32k|      } else {
  118|    843|        w = val[l];
  119|  17.8k|        for (int i = l + 1; i <= r; ++i) w = std::min(w, val[i]);
                                                  ^16.9k^16.9k
  ------------------
  |  Branch (119:29): [True: 95.26%, False: 4.74%]
  ------------------
  120|    843|      }
  121|  2.92M|      u64 sum = b[w];
  122|  2.92M|      --l;
  123|  24.7M|      for (; l; l -= l & -l) sum += c[l];
                              ^21.7M       ^21.7M
  ------------------
  |  Branch (123:14): [True: 88.18%, False: 11.82%]
  ------------------
  124|  30.2M|      for (; r; r -= r & -r) sum += c[r];
                              ^27.2M       ^27.2M
  ------------------
  |  Branch (124:14): [True: 90.33%, False: 9.67%]
  ------------------
  125|  22.5M|      for (; w; w -= w & -w) sum -= c[w] * 2;
                              ^19.6M       ^19.6M
  ------------------
  |  Branch (125:14): [True: 87.08%, False: 12.92%]
  ------------------
  126|  2.92M|      wt.ud(sum);
  127|  2.92M|    }
  128|  5.33M|  }
  129|     19|  return 0;
  130|     19|}