/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|  2.32k|  Segment(Vertex v) : a{v.a}, b{v.b}, c{v.b} {}
   17|  6.45k|  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|  5.06k|auto operator+(const Segment &l, const Segment &r) -> Segment {
   25|  5.06k|  u32 x = u64(l.a) * r.a % P;
   26|  5.06k|  u32 y = (u64(l.a) * r.b + l.b) % P;
   27|  5.06k|  u32 z = (u64(r.a) * l.c + r.c) % P;
   28|  5.06k|  return {x, y, z};
   29|  5.06k|}
   30|  2.13k|auto operator+(const Segment &l, u32 r) -> u32 {
   31|  2.13k|  return (u64(l.a) * r + l.b) % P;
   32|  2.13k|}
   33|    696|auto operator+(u32 l, const Segment &r) -> u32 {
   34|    696|  return (u64(r.a) * l + r.c) % P;
   35|    696|}
   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|     88|def build_step_1(int u, int p) -> void {
   53|     88|  size[u] = 1;
   54|    262|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^174
  ------------------
  |  Branch (54:25): [True: 66.41%, False: 33.59%]
  ------------------
   55|    174|    int v = edge[e].to;
   56|    174|    if (v != p) {
  ------------------
  |  Branch (56:9): [True: 50.00%, False: 50.00%]
  ------------------
   57|     87|      build_step_1(v, u);
   58|     87|      size[u] += size[v];
   59|     87|      if (heavy[u] == 0 || size[v] > size[heavy[u]]) {
                                         ^44
  ------------------
  |  Branch (59:11): [True: 49.43%, False: 50.57%]
  |  Branch (59:28): [True: 43.18%, False: 56.82%]
  ------------------
   60|     62|        heavy[u] = v;
   61|     62|      }
   62|     87|    }
   63|    174|  }
   64|     88|}
   65|       |
   66|     88|def build_step_2(int u, int w, int p, int d) -> void {
   67|     88|  int i = ++id;
   68|     88|  node2id[u] = i;
   69|     88|  depth[i] = d;
   70|     88|  ances[i] = node2id[w];
   71|     88|  parent[i] = node2id[p];
   72|     88|  node[i].v = {a[u], b[u]};
   73|    262|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^174
  ------------------
  |  Branch (73:25): [True: 66.41%, False: 33.59%]
  ------------------
   74|    174|    int v = edge[e].to;
   75|    174|    if (v != p && v != heavy[u]) {
                                ^87
  ------------------
  |  Branch (75:9): [True: 50.00%, False: 50.00%]
  |  Branch (75:19): [True: 50.57%, False: 49.43%]
  ------------------
   76|     44|      build_step_2(v, v, u, d + 1);
   77|     44|    }
   78|    174|  }
   79|     88|  priority[i] = u8(log(i ^ (id + 1)));
   80|     88|  if (u != w) {
  ------------------
  |  Branch (80:7): [True: 48.86%, False: 51.14%]
  ------------------
   81|     43|    int p = parent[i];
   82|     43|    int l = 0;
   83|     66|    while (p && priority[p] < priority[i]) {
                              ^53
  ------------------
  |  Branch (83:12): [True: 80.30%, False: 19.70%]
  |  Branch (83:17): [True: 43.40%, False: 56.60%]
  ------------------
   84|     23|      l = p;
   85|     23|      p = node[p].p;
   86|     23|    }
   87|     43|    node[p].r = i;
   88|     43|    node[i].p = p;
   89|     43|    node[i].l = l;
   90|     43|    node[l].p = i;
   91|     43|  }
   92|     88|  if (int v = heavy[u]; v) {
  ------------------
  |  Branch (92:25): [True: 48.86%, False: 51.14%]
  ------------------
   93|     43|    build_step_2(v, w, u, d + 1);
   94|     43|  }
   95|     88|}
   96|       |
   97|  1.32k|def maintain(int u) -> void {
   98|  1.32k|  node[u].s = (node[u].t = node[node[u].l].s + node[u].v) + node[node[u].r].s;
   99|  1.32k|}
  100|       |
  101|  1.66k|template <typename T> T apply(int k, T x) {
  102|  4.38k|  for (int u = k; u; u = node[u].p) {
                                   ^2.71k
  ------------------
  |  Branch (102:19): [True: 61.78%, False: 38.22%]
  ------------------
  |  Branch (102:19): [True: 62.10%, False: 37.90%]
  ------------------
  103|  2.71k|    if (u <= k) {
  ------------------
  |  Branch (103:9): [True: 78.99%, False: 21.01%]
  ------------------
  |  Branch (103:9): [True: 77.95%, False: 22.05%]
  ------------------
  104|  2.13k|      x = node[u].t + x;
  105|  2.13k|    }
  106|  2.71k|  }
  107|  1.66k|  return x;
  108|  1.66k|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyIjEET_iS1_:
  |  101|    860|template <typename T> T apply(int k, T x) {
  |  102|  2.25k|  for (int u = k; u; u = node[u].p) {
  |                                   ^1.39k
  |  ------------------
  |  |  Branch (102:19): [True: 61.78%, False: 38.22%]
  |  ------------------
  |  103|  1.39k|    if (u <= k) {
  |  ------------------
  |  |  Branch (103:9): [True: 78.99%, False: 21.01%]
  |  ------------------
  |  104|  1.09k|      x = node[u].t + x;
  |  105|  1.09k|    }
  |  106|  1.39k|  }
  |  107|    860|  return x;
  |  108|    860|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyINS_7SegmentEEET_iS2_:
  |  101|    808|template <typename T> T apply(int k, T x) {
  |  102|  2.13k|  for (int u = k; u; u = node[u].p) {
  |                                   ^1.32k
  |  ------------------
  |  |  Branch (102:19): [True: 62.10%, False: 37.90%]
  |  ------------------
  |  103|  1.32k|    if (u <= k) {
  |  ------------------
  |  |  Branch (103:9): [True: 77.95%, False: 22.05%]
  |  ------------------
  |  104|  1.03k|      x = node[u].t + x;
  |  105|  1.03k|    }
  |  106|  1.32k|  }
  |  107|    808|  return x;
  |  108|    808|}
  ------------------
  109|       |
  110|    696|template <typename T> T apply(int l, int r, T x) {
  111|    696|  Segment t = {1, 0, 0};
  112|    696|  int u = l;
  113|    696|  int v = r;
  114|  1.62k|  while (u != v) {
  ------------------
  |  Branch (114:10): [True: 52.18%, False: 47.82%]
  ------------------
  |  Branch (114:10): [True: 62.72%, False: 37.28%]
  ------------------
  115|    925|    if (priority[u] < priority[v]) {
  ------------------
  |  Branch (115:9): [True: 35.90%, False: 64.10%]
  ------------------
  |  Branch (115:9): [True: 37.58%, False: 62.42%]
  ------------------
  116|    340|      if (l <= u) {
  ------------------
  |  Branch (116:11): [True: 88.34%, False: 11.66%]
  ------------------
  |  Branch (116:11): [True: 88.70%, False: 11.30%]
  ------------------
  117|    301|        t = (t + node[u].v) + node[node[u].r].s;
  118|    301|      }
  119|    340|      u = node[u].p;
  120|    585|    } else {
  121|    585|      if (v <= r) {
  ------------------
  |  Branch (121:11): [True: 70.79%, False: 29.21%]
  ------------------
  |  Branch (121:11): [True: 74.15%, False: 25.85%]
  ------------------
  122|    424|        x = node[v].t + x;
  123|    424|      }
  124|    585|      v = node[v].p;
  125|    585|    }
  126|    925|  }
  127|    696|  x = t + (node[u].v + x);
  128|    696|  return x;
  129|    696|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyIjEET_iiS1_:
  |  110|    416|template <typename T> T apply(int l, int r, T x) {
  |  111|    416|  Segment t = {1, 0, 0};
  |  112|    416|  int u = l;
  |  113|    416|  int v = r;
  |  114|    870|  while (u != v) {
  |  ------------------
  |  |  Branch (114:10): [True: 52.18%, False: 47.82%]
  |  ------------------
  |  115|    454|    if (priority[u] < priority[v]) {
  |  ------------------
  |  |  Branch (115:9): [True: 35.90%, False: 64.10%]
  |  ------------------
  |  116|    163|      if (l <= u) {
  |  ------------------
  |  |  Branch (116:11): [True: 88.34%, False: 11.66%]
  |  ------------------
  |  117|    144|        t = (t + node[u].v) + node[node[u].r].s;
  |  118|    144|      }
  |  119|    163|      u = node[u].p;
  |  120|    291|    } else {
  |  121|    291|      if (v <= r) {
  |  ------------------
  |  |  Branch (121:11): [True: 70.79%, False: 29.21%]
  |  ------------------
  |  122|    206|        x = node[v].t + x;
  |  123|    206|      }
  |  124|    291|      v = node[v].p;
  |  125|    291|    }
  |  126|    454|  }
  |  127|    416|  x = t + (node[u].v + x);
  |  128|    416|  return x;
  |  129|    416|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyINS_7SegmentEEET_iiS2_:
  |  110|    280|template <typename T> T apply(int l, int r, T x) {
  |  111|    280|  Segment t = {1, 0, 0};
  |  112|    280|  int u = l;
  |  113|    280|  int v = r;
  |  114|    751|  while (u != v) {
  |  ------------------
  |  |  Branch (114:10): [True: 62.72%, False: 37.28%]
  |  ------------------
  |  115|    471|    if (priority[u] < priority[v]) {
  |  ------------------
  |  |  Branch (115:9): [True: 37.58%, False: 62.42%]
  |  ------------------
  |  116|    177|      if (l <= u) {
  |  ------------------
  |  |  Branch (116:11): [True: 88.70%, False: 11.30%]
  |  ------------------
  |  117|    157|        t = (t + node[u].v) + node[node[u].r].s;
  |  118|    157|      }
  |  119|    177|      u = node[u].p;
  |  120|    294|    } else {
  |  121|    294|      if (v <= r) {
  |  ------------------
  |  |  Branch (121:11): [True: 74.15%, False: 25.85%]
  |  ------------------
  |  122|    218|        x = node[v].t + x;
  |  123|    218|      }
  |  124|    294|      v = node[v].p;
  |  125|    294|    }
  |  126|    471|  }
  |  127|    280|  x = t + (node[u].v + x);
  |  128|    280|  return x;
  |  129|    280|}
  ------------------
  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|     89|  for (int i = 0; i < n; ++i) a[i] = rd.uw(), b[i] = rd.uw();
                                       ^88  ^88
  ------------------
  |  Branch (145:19): [True: 98.88%, False: 1.12%]
  ------------------
  146|     88|  for (int i = 1; i < n; ++i) {
                                       ^87
  ------------------
  |  Branch (146:19): [True: 98.86%, False: 1.14%]
  ------------------
  147|     87|    int u = rd.uh();
  148|     87|    int v = rd.uh();
  149|     87|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  150|     87|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  151|     87|  }
  152|      1|  build_step_1(0, 0);
  153|      1|  build_step_2(0, 0, 0, 0);
  154|     89|  for (int i = 1; i <= n; ++i) {
                                        ^88
  ------------------
  |  Branch (154:19): [True: 98.88%, False: 1.12%]
  ------------------
  155|     88|    if (node[i].r == 0) {
  ------------------
  |  Branch (155:9): [True: 70.45%, False: 29.55%]
  ------------------
  156|    150|      for (int u = i; u && u <= i; u = node[u].p) {
                                         ^105    ^88
  ------------------
  |  Branch (156:23): [True: 70.00%, False: 30.00%]
  |  Branch (156:28): [True: 83.81%, False: 16.19%]
  ------------------
  157|     88|        maintain(u);
  158|     88|      }
  159|     62|    }
  160|     88|  }
  161|  1.42k|  while (q--) {
  ------------------
  |  Branch (161:10): [True: 99.93%, False: 0.07%]
  ------------------
  162|  1.41k|    let t = rd.u1();
  163|  1.41k|    if (t == 0) {
  ------------------
  |  Branch (163:9): [True: 50.95%, False: 49.05%]
  ------------------
  164|    723|      int u = node2id[rd.uh()];
  165|    723|      node[u].v = {rd.uw(), rd.uw()};
  166|  1.96k|      for (; u; u = node[u].p) {
                              ^1.23k
  ------------------
  |  Branch (166:14): [True: 63.13%, False: 36.87%]
  ------------------
  167|  1.23k|        maintain(u);
  168|  1.23k|      }
  169|    723|    }
  170|  1.41k|    if (t == 1) {
  ------------------
  |  Branch (170:9): [True: 49.05%, False: 50.95%]
  ------------------
  171|    696|      int u = node2id[rd.uh()];
  172|    696|      int v = node2id[rd.uh()];
  173|    696|      u32 x = rd.uw();
  174|    696|      Segment f = {1, 0, 0};
  175|  2.36k|      while (ances[u] != ances[v]) {
  ------------------
  |  Branch (175:14): [True: 70.56%, False: 29.44%]
  ------------------
  176|  1.66k|        if (depth[ances[u]] >= depth[ances[v]]) {
  ------------------
  |  Branch (176:13): [True: 51.56%, False: 48.44%]
  ------------------
  177|    860|          x = apply(u, x);
  178|    860|          u = parent[ances[u]];
  179|    860|        } else {
  180|    808|          f = apply(v, f);
  181|    808|          v = parent[ances[v]];
  182|    808|        }
  183|  1.66k|      }
  184|    696|      if (u >= v) {
  ------------------
  |  Branch (184:11): [True: 59.77%, False: 40.23%]
  ------------------
  185|    416|        x = apply(v, u, x);
  186|    416|      } else {
  187|    280|        f = apply(u, v, f);
  188|    280|      }
  189|    696|      x = x + f;
  190|    696|      wt.uw(x);
  191|    696|    }
  192|  1.41k|  }
  193|      1|  return 0;
  194|      1|}