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