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