/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|   197k|  auto operator+(const Node &t) const -> Node {
   13|   197k|    u32 x = u64(a) * t.a % P;
   14|   197k|    u32 y = (u64(a) * t.b + b) % P;
   15|   197k|    u32 z = (u64(t.a) * c + t.c) % P;
   16|   197k|    return {x, y, z};
   17|   197k|  }
   18|       |} node[N * 2];
   19|      0|auto operator+(const Node &l, u32 r) -> u32 { return (u64(l.a) * r + l.b) % P; }
   20|  1.80M|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|   199k|def build_step_1(int u, int p) -> void {
   37|   199k|  size[u] = 1;
   38|   599k|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^399k
  ------------------
  |  Branch (38:25): [True: 66.67%, False: 33.33%]
  ------------------
   39|   399k|    int v = edge[e].to;
   40|   399k|    if (v != p) {
  ------------------
  |  Branch (40:9): [True: 50.00%, False: 50.00%]
  ------------------
   41|   199k|      build_step_1(v, u);
   42|   199k|      size[u] += size[v];
   43|   199k|      if (heavy[u] == 0 || size[v] > size[heavy[u]]) {
                                         ^446
  ------------------
  |  Branch (43:11): [True: 99.78%, False: 0.22%]
  |  Branch (43:28): [True: 99.55%, False: 0.45%]
  ------------------
   44|   199k|        heavy[u] = v;
   45|   199k|      }
   46|   199k|    }
   47|   399k|  }
   48|   199k|}
   49|       |
   50|   199k|def build_step_2(int u, int w, int p, int d) -> void {
   51|   199k|  int i = id++;
   52|   199k|  node2id[u] = i;
   53|   199k|  depth[i] = d;
   54|   199k|  int anc = ances[i] = node2id[w];
   55|   199k|  parent[i] = node2id[p];
   56|   199k|  node[i * 2 + 1] = {a[u], b[u], b[u]};
   57|   199k|  let a = node + anc * 2;
   58|   199k|  int k = (i - anc) * 2 + 1;
   59|   397k|  for (int j = 1; k & (j * 2); k -= j, j *= 2) {
                                             ^197k
  ------------------
  |  Branch (59:19): [True: 49.76%, False: 50.24%]
  ------------------
   60|   197k|    a[k - j] = a[k - j * 2] + a[k];
   61|   197k|  }
   62|   199k|  if (int v = heavy[u]; v) {
  ------------------
  |  Branch (62:25): [True: 99.78%, False: 0.22%]
  ------------------
   63|   199k|    build_step_2(v, w, u, d + 1);
   64|   199k|  }
   65|   599k|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^399k
  ------------------
  |  Branch (65:25): [True: 66.67%, False: 33.33%]
  ------------------
   66|   399k|    int v = edge[e].to;
   67|   399k|    if (v != p && v != heavy[u]) {
                                ^199k
  ------------------
  |  Branch (67:9): [True: 50.00%, False: 50.00%]
  |  Branch (67:19): [True: 0.22%, False: 99.78%]
  ------------------
   68|    446|      build_step_2(v, v, u, d + 1);
   69|    446|    }
   70|   399k|  }
   71|   199k|}
   72|       |
   73|      0|def apply_1(int i, u32 x) -> u32 {
   74|      0|  int anc = ances[i];
   75|      0|  let a = node + anc * 2;
   76|      0|  int r = (i - anc) * 2 + 2;
   77|      0|  for (; r; r -= r & -r) {
  ------------------
  |  Branch (77:10): [True: 0.00%, False: 0.00%]
  ------------------
   78|      0|    x = a[r - (r & -r) / 2] + x;
   79|      0|  }
   80|      0|  return x;
   81|      0|}
   82|       |
   83|   600k|def apply_2(int i, u32 x) -> u32 {
   84|   600k|  int anc = ances[i];
   85|   600k|  let a = node + anc * 2;
   86|   600k|  int r = (i - anc) * 2 + 2;
   87|  2.40M|  for (int k = 0; k < r;) {
  ------------------
  |  Branch (87:19): [True: 75.00%, False: 25.00%]
  ------------------
   88|  1.80M|    int t = 1 << log(r - k);
   89|  1.80M|    x = x + a[k + t / 2];
   90|  1.80M|    k += t;
   91|  1.80M|  }
   92|   600k|  return x;
   93|   600k|}
   94|       |
   95|      0|def apply_1(int i, int j, u32 x) -> u32 {
   96|      0|  int anc = ances[i];
   97|      0|  if (i == anc) return apply_1(j, x);
  ------------------
  |  Branch (97:7): [True: 0.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|      0|}
  112|       |
  113|   200k|def apply_2(int i, int j, u32 x) -> u32 {
  114|   200k|  int anc = ances[i];
  115|   200k|  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|   200k|}
  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|   199k|  for (int i = 0; i < n; ++i) a[i] = rd.uw(), b[i] = rd.uw();
                                       ^199k^199k
  ------------------
  |  Branch (143:19): [True: 100.00%, False: 0.00%]
  ------------------
  144|   199k|  for (int i = 1; i < n; ++i) {
                                       ^199k
  ------------------
  |  Branch (144:19): [True: 100.00%, False: 0.00%]
  ------------------
  145|   199k|    int u = rd.uh();
  146|   199k|    int v = rd.uh();
  147|   199k|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  148|   199k|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  149|   199k|  }
  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|   199k|  for (int i = 0; i < n; ++i) size[ances[i]]++;
                                       ^199k^199k
  ------------------
  |  Branch (153:19): [True: 100.00%, False: 0.00%]
  ------------------
  154|   200k|  while (q--) {
  ------------------
  |  Branch (154:10): [True: 100.00%, False: 0.00%]
  ------------------
  155|   200k|    let t = rd.u1();
  156|   200k|    if (t == 0) {
  ------------------
  |  Branch (156:9): [True: 0.00%, False: 100.00%]
  ------------------
  157|      0|      int i = node2id[rd.uh()];
  158|      0|      u32 c = rd.uw();
  159|      0|      u32 d = rd.uw();
  160|      0|      int anc = ances[i];
  161|      0|      let a = node + anc * 2;
  162|      0|      int n = size[anc];
  163|      0|      int k = (i - anc) * 2 + 1;
  164|      0|      a[k] = {c, d, d};
  165|      0|      for (int j = 1;; j *= 2) {
  166|      0|        if (k & (j * 2)) {
  ------------------
  |  Branch (166:13): [True: 0.00%, False: 0.00%]
  ------------------
  167|      0|          a[k - j] = a[k - j * 2] + a[k];
  168|      0|          k -= j;
  169|      0|        } else {
  170|      0|          if (k + j * 3 > n * 2) break;
  ------------------
  |  Branch (170:15): [True: 0.00%, False: 0.00%]
  ------------------
  171|      0|          a[k + j] = a[k] + a[k + j * 2];
  172|      0|          k += j;
  173|      0|        }
  174|      0|      }
  175|      0|    }
  176|   200k|    if (t == 1) {
  ------------------
  |  Branch (176:9): [True: 100.00%, False: 0.00%]
  ------------------
  177|   200k|      int u = node2id[rd.uh()];
  178|   200k|      int v = node2id[rd.uh()];
  179|   200k|      u32 x = rd.uw();
  180|   200k|      int vec[20], top{};
  181|   600k|      while (ances[u] != ances[v]) {
  ------------------
  |  Branch (181:14): [True: 66.67%, False: 33.33%]
  ------------------
  182|   400k|        if (depth[ances[u]] > depth[ances[v]]) {
  ------------------
  |  Branch (182:13): [True: 0.00%, False: 100.00%]
  ------------------
  183|      0|          x = apply_1(u, x);
  184|      0|          u = parent[ances[u]];
  185|   400k|        } else {
  186|   400k|          vec[top++] = v;
  187|   400k|          v = parent[ances[v]];
  188|   400k|        }
  189|   400k|      }
  190|   200k|      if (u > v) {
  ------------------
  |  Branch (190:11): [True: 0.00%, False: 100.00%]
  ------------------
  191|      0|        x = apply_1(v, u, x);
  192|   200k|      } else {
  193|   200k|        x = apply_2(u, v, x);
  194|   200k|      }
  195|   600k|      while (top--) {
  ------------------
  |  Branch (195:14): [True: 66.67%, False: 33.33%]
  ------------------
  196|   400k|        x = apply_2(vec[top], x);
  197|   400k|      }
  198|   200k|      wt.uw(x);
  199|   200k|    }
  200|   200k|  }
  201|      1|  return 0;
  202|      1|}