/tmp/solutions/build/vertex_set_path_composite-main.cpp:
    1|       |#include <common.h>
    2|       |#include <toy/bit.h>
    3|       |prelude;
    4|       |
    5|       |namespace {
    6|       |
    7|       |constexpr int N = 2e5;
    8|       |constexpr int P = 998244353;
    9|       |
   10|       |struct Node {
   11|       |  u32 a, b, c;
   12|      4|  auto operator+(const Node &t) const -> Node {
   13|      4|    u32 x = u64(a) * t.a % P;
   14|      4|    u32 y = (u64(a) * t.b + b) % P;
   15|      4|    u32 z = (u64(t.a) * c + t.c) % P;
   16|      4|    return {x, y, z};
   17|      4|  }
   18|       |} node[N * 2];
   19|      8|auto operator+(const Node &l, u32 r) -> u32 { return (u64(l.a) * r + l.b) % P; }
   20|     10|auto operator+(u32 l, const Node &r) -> u32 { return (u64(r.a) * l + r.c) % P; }
   21|       |u32 a[N];
   22|       |u32 b[N];
   23|       |int head[N];
   24|       |int size[N];
   25|       |int depth[N];
   26|       |int heavy[N];
   27|       |int ances[N];
   28|       |int parent[N];
   29|       |int node2id[N];
   30|       |int id;
   31|       |struct {
   32|       |  int to;
   33|       |  int next;
   34|       |} edge[N * 2];
   35|       |
   36|      7|def build_step_1(int u, int p) -> void {
   37|      7|  size[u] = 1;
   38|     19|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^12
  ------------------
  |  Branch (38:25): [True: 63.16%, False: 36.84%]
  ------------------
   39|     12|    int v = edge[e].to;
   40|     12|    if (v != p) {
  ------------------
  |  Branch (40:9): [True: 50.00%, False: 50.00%]
  ------------------
   41|      6|      build_step_1(v, u);
   42|      6|      size[u] += size[v];
   43|      6|      if (heavy[u] == 0 || size[v] > size[heavy[u]]) {
                                         ^2
  ------------------
  |  Branch (43:11): [True: 66.67%, False: 33.33%]
  |  Branch (43:28): [True: 0.00%, False: 100.00%]
  ------------------
   44|      4|        heavy[u] = v;
   45|      4|      }
   46|      6|    }
   47|     12|  }
   48|      7|}
   49|       |
   50|      7|def build_step_2(int u, int w, int p, int d) -> void {
   51|      7|  int i = id++;
   52|      7|  node2id[u] = i;
   53|      7|  depth[i] = d;
   54|      7|  int anc = ances[i] = node2id[w];
   55|      7|  parent[i] = node2id[p];
   56|      7|  node[i * 2 + 1] = {a[u], b[u], b[u]};
   57|      7|  let a = node + anc * 2;
   58|      7|  int k = (i - anc) * 2 + 1;
   59|     10|  for (int j = 1; k & (j * 2); k -= j, j *= 2) {
                                             ^3
  ------------------
  |  Branch (59:19): [True: 30.00%, False: 70.00%]
  ------------------
   60|      3|    a[k - j] = a[k - j * 2] + a[k];
   61|      3|  }
   62|      7|  if (int v = heavy[u]; v) {
  ------------------
  |  Branch (62:25): [True: 57.14%, False: 42.86%]
  ------------------
   63|      4|    build_step_2(v, w, u, d + 1);
   64|      4|  }
   65|     19|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^12
  ------------------
  |  Branch (65:25): [True: 63.16%, False: 36.84%]
  ------------------
   66|     12|    int v = edge[e].to;
   67|     12|    if (v != p && v != heavy[u]) {
                                ^6
  ------------------
  |  Branch (67:9): [True: 50.00%, False: 50.00%]
  |  Branch (67:19): [True: 33.33%, False: 66.67%]
  ------------------
   68|      2|      build_step_2(v, v, u, d + 1);
   69|      2|    }
   70|     12|  }
   71|      7|}
   72|       |
   73|      6|def apply_1(int i, u32 x) -> u32 {
   74|      6|  int anc = ances[i];
   75|      6|  let a = node + anc * 2;
   76|      6|  int r = (i - anc) * 2 + 2;
   77|     14|  for (; r; r -= r & -r) {
                          ^8
  ------------------
  |  Branch (77:10): [True: 57.14%, False: 42.86%]
  ------------------
   78|      8|    x = a[r - (r & -r) / 2] + x;
   79|      8|  }
   80|      6|  return x;
   81|      6|}
   82|       |
   83|      8|def apply_2(int i, u32 x) -> u32 {
   84|      8|  int anc = ances[i];
   85|      8|  let a = node + anc * 2;
   86|      8|  int r = (i - anc) * 2 + 2;
   87|     18|  for (int k = 0; k < r;) {
  ------------------
  |  Branch (87:19): [True: 55.56%, False: 44.44%]
  ------------------
   88|     10|    int t = 1 << log(r - k);
   89|     10|    x = x + a[k + t / 2];
   90|     10|    k += t;
   91|     10|  }
   92|      8|  return x;
   93|      8|}
   94|       |
   95|      2|def apply_1(int i, int j, u32 x) -> u32 {
   96|      2|  int anc = ances[i];
   97|      2|  if (i == anc) return apply_1(j, x);
  ------------------
  |  Branch (97:7): [True: 100.00%, False: 0.00%]
  ------------------
   98|      0|  let a = node + anc * 2;
   99|      0|  int l = (i - anc) * 2 - 1;
  100|      0|  int r = (j - anc) * 2 + 3;
  101|      0|  int k = (-1 << log(l ^ r)) & r;
  102|      0|  for (--r; r > k; r -= r & -r) {
  ------------------
  |  Branch (102:13): [True: 0.00%, False: 0.00%]
  ------------------
  103|      0|    x = a[r - (r & -r) / 2] + x;
  104|      0|  }
  105|      0|  for (++l; k > l;) {
  ------------------
  |  Branch (105:13): [True: 0.00%, False: 0.00%]
  ------------------
  106|      0|    int t = 1 << log(k - l);
  107|      0|    x = a[k - t / 2] + x;
  108|      0|    k -= t;
  109|      0|  }
  110|      0|  return x;
  111|      2|}
  112|       |
  113|      4|def apply_2(int i, int j, u32 x) -> u32 {
  114|      4|  int anc = ances[i];
  115|      4|  if (i == anc) return apply_2(j, x);
  ------------------
  |  Branch (115:7): [True: 100.00%, False: 0.00%]
  ------------------
  116|      0|  let a = node + anc * 2;
  117|      0|  int l = (i - anc) * 2 - 1;
  118|      0|  int r = (j - anc) * 2 + 3;
  119|      0|  int k = (-1 << log(l ^ r)) & r;
  120|      0|  for (++l; l < k; l += l & -l) {
  ------------------
  |  Branch (120:13): [True: 0.00%, False: 0.00%]
  ------------------
  121|      0|    x = x + a[l + (l & -l) / 2];
  122|      0|  }
  123|      0|  for (--r; k < r;) {
  ------------------
  |  Branch (123:13): [True: 0.00%, False: 0.00%]
  ------------------
  124|      0|    int t = 1 << log(r - k);
  125|      0|    x = x + a[k + t / 2];
  126|      0|    k += t;
  127|      0|  }
  128|      0|  return x;
  129|      4|}
  130|       |
  131|       |} // namespace
  132|       |
  133|      1|int main() {
  134|      1|  rd rd;
  135|      1|  wt wt;
  136|      1|  int n = rd.uh();
  137|      1|  int q = rd.uh();
  138|      1|#ifdef LOCAL
  139|      1|  id = 0;
  140|      1|  std::memset(head, 0, 4 * n);
  141|      1|  std::memset(heavy, 0, 4 * n);
  142|      1|#endif
  143|      8|  for (int i = 0; i < n; ++i) a[i] = rd.uw(), b[i] = rd.uw();
                                       ^7   ^7
  ------------------
  |  Branch (143:19): [True: 87.50%, False: 12.50%]
  ------------------
  144|      7|  for (int i = 1; i < n; ++i) {
                                       ^6
  ------------------
  |  Branch (144:19): [True: 85.71%, False: 14.29%]
  ------------------
  145|      6|    int u = rd.uh();
  146|      6|    int v = rd.uh();
  147|      6|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  148|      6|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  149|      6|  }
  150|      1|  build_step_1(0, 0);
  151|      1|  build_step_2(0, 0, 0, 0);
  152|      1|  std::memset(size, 0, sizeof(int) * n);
  153|      8|  for (int i = 0; i < n; ++i) size[ances[i]]++;
                                       ^7   ^7
  ------------------
  |  Branch (153:19): [True: 87.50%, False: 12.50%]
  ------------------
  154|      8|  while (q--) {
  ------------------
  |  Branch (154:10): [True: 87.50%, False: 12.50%]
  ------------------
  155|      7|    let t = rd.u1();
  156|      7|    if (t == 0) {
  ------------------
  |  Branch (156:9): [True: 14.29%, False: 85.71%]
  ------------------
  157|      1|      int i = node2id[rd.uh()];
  158|      1|      u32 c = rd.uw();
  159|      1|      u32 d = rd.uw();
  160|      1|      int anc = ances[i];
  161|      1|      let a = node + anc * 2;
  162|      1|      int n = size[anc];
  163|      1|      int k = (i - anc) * 2 + 1;
  164|      1|      a[k] = {c, d, d};
  165|      2|      for (int j = 1;; j *= 2) {
                                     ^1
  166|      2|        if (k & (j * 2)) {
  ------------------
  |  Branch (166:13): [True: 0.00%, False: 100.00%]
  ------------------
  167|      0|          a[k - j] = a[k - j * 2] + a[k];
  168|      0|          k -= j;
  169|      2|        } else {
  170|      2|          if (k + j * 3 > n * 2) break;
                                               ^1
  ------------------
  |  Branch (170:15): [True: 50.00%, False: 50.00%]
  ------------------
  171|      1|          a[k + j] = a[k] + a[k + j * 2];
  172|      1|          k += j;
  173|      1|        }
  174|      2|      }
  175|      1|    }
  176|      7|    if (t == 1) {
  ------------------
  |  Branch (176:9): [True: 85.71%, False: 14.29%]
  ------------------
  177|      6|      int u = node2id[rd.uh()];
  178|      6|      int v = node2id[rd.uh()];
  179|      6|      u32 x = rd.uw();
  180|      6|      int vec[20], top{};
  181|     14|      while (ances[u] != ances[v]) {
  ------------------
  |  Branch (181:14): [True: 57.14%, False: 42.86%]
  ------------------
  182|      8|        if (depth[ances[u]] > depth[ances[v]]) {
  ------------------
  |  Branch (182:13): [True: 50.00%, False: 50.00%]
  ------------------
  183|      4|          x = apply_1(u, x);
  184|      4|          u = parent[ances[u]];
  185|      4|        } else {
  186|      4|          vec[top++] = v;
  187|      4|          v = parent[ances[v]];
  188|      4|        }
  189|      8|      }
  190|      6|      if (u > v) {
  ------------------
  |  Branch (190:11): [True: 33.33%, False: 66.67%]
  ------------------
  191|      2|        x = apply_1(v, u, x);
  192|      4|      } else {
  193|      4|        x = apply_2(u, v, x);
  194|      4|      }
  195|     10|      while (top--) {
  ------------------
  |  Branch (195:14): [True: 40.00%, False: 60.00%]
  ------------------
  196|      4|        x = apply_2(vec[top], x);
  197|      4|      }
  198|      6|      wt.uw(x);
  199|      6|    }
  200|      7|  }
  201|      1|  return 0;
  202|      1|}