/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|   637k|  Segment(Vertex v) : a{v.a}, b{v.b}, c{v.b} {}
   17|  3.91M|  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|  3.53M|auto operator+(const Segment &l, const Segment &r) -> Segment {
   25|  3.53M|  u32 x = u64(l.a) * r.a % P;
   26|  3.53M|  u32 y = (u64(l.a) * r.b + l.b) % P;
   27|  3.53M|  u32 z = (u64(r.a) * l.c + r.c) % P;
   28|  3.53M|  return {x, y, z};
   29|  3.53M|}
   30|  2.64M|auto operator+(const Segment &l, u32 r) -> u32 {
   31|  2.64M|  return (u64(l.a) * r + l.b) % P;
   32|  2.64M|}
   33|   190k|auto operator+(u32 l, const Segment &r) -> u32 {
   34|   190k|  return (u64(r.a) * l + r.c) % P;
   35|   190k|}
   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|   200k|def build_step_1(int u, int p) -> void {
   53|   200k|  size[u] = 1;
   54|   599k|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^399k
  ------------------
  |  Branch (54:25): [True: 66.67%, False: 33.33%]
  ------------------
   55|   399k|    int v = edge[e].to;
   56|   399k|    if (v != p) {
  ------------------
  |  Branch (56:9): [True: 50.00%, False: 50.00%]
  ------------------
   57|   199k|      build_step_1(v, u);
   58|   199k|      size[u] += size[v];
   59|   199k|      if (heavy[u] == 0 || size[v] > size[heavy[u]]) {
                                         ^32.7k
  ------------------
  |  Branch (59:11): [True: 83.62%, False: 16.38%]
  |  Branch (59:28): [True: 18.21%, False: 81.79%]
  ------------------
   60|   173k|        heavy[u] = v;
   61|   173k|      }
   62|   199k|    }
   63|   399k|  }
   64|   200k|}
   65|       |
   66|   200k|def build_step_2(int u, int w, int p, int d) -> void {
   67|   200k|  int i = ++id;
   68|   200k|  node2id[u] = i;
   69|   200k|  depth[i] = d;
   70|   200k|  ances[i] = node2id[w];
   71|   200k|  parent[i] = node2id[p];
   72|   200k|  node[i].v = {a[u], b[u]};
   73|   599k|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^399k
  ------------------
  |  Branch (73:25): [True: 66.67%, False: 33.33%]
  ------------------
   74|   399k|    int v = edge[e].to;
   75|   399k|    if (v != p && v != heavy[u]) {
                                ^199k
  ------------------
  |  Branch (75:9): [True: 50.00%, False: 50.00%]
  |  Branch (75:19): [True: 16.38%, False: 83.62%]
  ------------------
   76|  32.7k|      build_step_2(v, v, u, d + 1);
   77|  32.7k|    }
   78|   399k|  }
   79|   200k|  priority[i] = u8(log(i ^ (id + 1)));
   80|   200k|  if (u != w) {
  ------------------
  |  Branch (80:7): [True: 83.62%, False: 16.38%]
  ------------------
   81|   167k|    int p = parent[i];
   82|   167k|    int l = 0;
   83|   310k|    while (p && priority[p] < priority[i]) {
                              ^294k
  ------------------
  |  Branch (83:12): [True: 94.78%, False: 5.22%]
  |  Branch (83:17): [True: 48.66%, False: 51.34%]
  ------------------
   84|   143k|      l = p;
   85|   143k|      p = node[p].p;
   86|   143k|    }
   87|   167k|    node[p].r = i;
   88|   167k|    node[i].p = p;
   89|   167k|    node[i].l = l;
   90|   167k|    node[l].p = i;
   91|   167k|  }
   92|   200k|  if (int v = heavy[u]; v) {
  ------------------
  |  Branch (92:25): [True: 83.62%, False: 16.38%]
  ------------------
   93|   167k|    build_step_2(v, w, u, d + 1);
   94|   167k|  }
   95|   200k|}
   96|       |
   97|   256k|def maintain(int u) -> void {
   98|   256k|  node[u].s = (node[u].t = node[node[u].l].s + node[u].v) + node[node[u].r].s;
   99|   256k|}
  100|       |
  101|  2.85M|template <typename T> T apply(int k, T x) {
  102|  8.88M|  for (int u = k; u; u = node[u].p) {
                                   ^6.02M
  ------------------
  |  Branch (102:19): [True: 67.82%, False: 32.18%]
  ------------------
  |  Branch (102:19): [True: 67.83%, False: 32.17%]
  ------------------
  103|  6.02M|    if (u <= k) {
  ------------------
  |  Branch (103:9): [True: 78.85%, False: 21.15%]
  ------------------
  |  Branch (103:9): [True: 78.84%, False: 21.16%]
  ------------------
  104|  4.75M|      x = node[u].t + x;
  105|  4.75M|    }
  106|  6.02M|  }
  107|  2.85M|  return x;
  108|  2.85M|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyIjEET_iS1_:
  |  101|  1.42M|template <typename T> T apply(int k, T x) {
  |  102|  4.44M|  for (int u = k; u; u = node[u].p) {
  |                                   ^3.01M
  |  ------------------
  |  |  Branch (102:19): [True: 67.82%, False: 32.18%]
  |  ------------------
  |  103|  3.01M|    if (u <= k) {
  |  ------------------
  |  |  Branch (103:9): [True: 78.85%, False: 21.15%]
  |  ------------------
  |  104|  2.37M|      x = node[u].t + x;
  |  105|  2.37M|    }
  |  106|  3.01M|  }
  |  107|  1.42M|  return x;
  |  108|  1.42M|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyINS_7SegmentEEET_iS2_:
  |  101|  1.42M|template <typename T> T apply(int k, T x) {
  |  102|  4.44M|  for (int u = k; u; u = node[u].p) {
  |                                   ^3.01M
  |  ------------------
  |  |  Branch (102:19): [True: 67.83%, False: 32.17%]
  |  ------------------
  |  103|  3.01M|    if (u <= k) {
  |  ------------------
  |  |  Branch (103:9): [True: 78.84%, False: 21.16%]
  |  ------------------
  |  104|  2.37M|      x = node[u].t + x;
  |  105|  2.37M|    }
  |  106|  3.01M|  }
  |  107|  1.42M|  return x;
  |  108|  1.42M|}
  ------------------
  109|       |
  110|   190k|template <typename T> T apply(int l, int r, T x) {
  111|   190k|  Segment t = {1, 0, 0};
  112|   190k|  int u = l;
  113|   190k|  int v = r;
  114|   620k|  while (u != v) {
  ------------------
  |  Branch (114:10): [True: 69.34%, False: 30.66%]
  ------------------
  |  Branch (114:10): [True: 69.25%, False: 30.75%]
  ------------------
  115|   429k|    if (priority[u] < priority[v]) {
  ------------------
  |  Branch (115:9): [True: 44.22%, False: 55.78%]
  ------------------
  |  Branch (115:9): [True: 44.40%, False: 55.60%]
  ------------------
  116|   190k|      if (l <= u) {
  ------------------
  |  Branch (116:11): [True: 100.00%, False: 0.00%]
  ------------------
  |  Branch (116:11): [True: 100.00%, False: 0.00%]
  ------------------
  117|   190k|        t = (t + node[u].v) + node[node[u].r].s;
  118|   190k|      }
  119|   190k|      u = node[u].p;
  120|   239k|    } else {
  121|   239k|      if (v <= r) {
  ------------------
  |  Branch (121:11): [True: 64.27%, False: 35.73%]
  ------------------
  |  Branch (121:11): [True: 64.13%, False: 35.87%]
  ------------------
  122|   153k|        x = node[v].t + x;
  123|   153k|      }
  124|   239k|      v = node[v].p;
  125|   239k|    }
  126|   429k|  }
  127|   190k|  x = t + (node[u].v + x);
  128|   190k|  return x;
  129|   190k|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyIjEET_iiS1_:
  |  110|  95.1k|template <typename T> T apply(int l, int r, T x) {
  |  111|  95.1k|  Segment t = {1, 0, 0};
  |  112|  95.1k|  int u = l;
  |  113|  95.1k|  int v = r;
  |  114|   310k|  while (u != v) {
  |  ------------------
  |  |  Branch (114:10): [True: 69.34%, False: 30.66%]
  |  ------------------
  |  115|   215k|    if (priority[u] < priority[v]) {
  |  ------------------
  |  |  Branch (115:9): [True: 44.22%, False: 55.78%]
  |  ------------------
  |  116|  95.1k|      if (l <= u) {
  |  ------------------
  |  |  Branch (116:11): [True: 100.00%, False: 0.00%]
  |  ------------------
  |  117|  95.1k|        t = (t + node[u].v) + node[node[u].r].s;
  |  118|  95.1k|      }
  |  119|  95.1k|      u = node[u].p;
  |  120|   119k|    } else {
  |  121|   119k|      if (v <= r) {
  |  ------------------
  |  |  Branch (121:11): [True: 64.27%, False: 35.73%]
  |  ------------------
  |  122|  77.0k|        x = node[v].t + x;
  |  123|  77.0k|      }
  |  124|   119k|      v = node[v].p;
  |  125|   119k|    }
  |  126|   215k|  }
  |  127|  95.1k|  x = t + (node[u].v + x);
  |  128|  95.1k|  return x;
  |  129|  95.1k|}
  ------------------
  | vertex_set_path_composite-logn.cpp:_ZN12_GLOBAL__N_15applyINS_7SegmentEEET_iiS2_:
  |  110|  95.4k|template <typename T> T apply(int l, int r, T x) {
  |  111|  95.4k|  Segment t = {1, 0, 0};
  |  112|  95.4k|  int u = l;
  |  113|  95.4k|  int v = r;
  |  114|   310k|  while (u != v) {
  |  ------------------
  |  |  Branch (114:10): [True: 69.25%, False: 30.75%]
  |  ------------------
  |  115|   214k|    if (priority[u] < priority[v]) {
  |  ------------------
  |  |  Branch (115:9): [True: 44.40%, False: 55.60%]
  |  ------------------
  |  116|  95.4k|      if (l <= u) {
  |  ------------------
  |  |  Branch (116:11): [True: 100.00%, False: 0.00%]
  |  ------------------
  |  117|  95.4k|        t = (t + node[u].v) + node[node[u].r].s;
  |  118|  95.4k|      }
  |  119|  95.4k|      u = node[u].p;
  |  120|   119k|    } else {
  |  121|   119k|      if (v <= r) {
  |  ------------------
  |  |  Branch (121:11): [True: 64.13%, False: 35.87%]
  |  ------------------
  |  122|  76.6k|        x = node[v].t + x;
  |  123|  76.6k|      }
  |  124|   119k|      v = node[v].p;
  |  125|   119k|    }
  |  126|   214k|  }
  |  127|  95.4k|  x = t + (node[u].v + x);
  |  128|  95.4k|  return x;
  |  129|  95.4k|}
  ------------------
  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|   200k|  for (int i = 0; i < n; ++i) a[i] = rd.uw(), b[i] = rd.uw();
                                       ^200k^200k
  ------------------
  |  Branch (145:19): [True: 100.00%, False: 0.00%]
  ------------------
  146|   200k|  for (int i = 1; i < n; ++i) {
                                       ^199k
  ------------------
  |  Branch (146:19): [True: 100.00%, False: 0.00%]
  ------------------
  147|   199k|    int u = rd.uh();
  148|   199k|    int v = rd.uh();
  149|   199k|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  150|   199k|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  151|   199k|  }
  152|      1|  build_step_1(0, 0);
  153|      1|  build_step_2(0, 0, 0, 0);
  154|   200k|  for (int i = 1; i <= n; ++i) {
                                        ^200k
  ------------------
  |  Branch (154:19): [True: 100.00%, False: 0.00%]
  ------------------
  155|   200k|    if (node[i].r == 0) {
  ------------------
  |  Branch (155:9): [True: 56.72%, False: 43.28%]
  ------------------
  156|   313k|      for (int u = i; u && u <= i; u = node[u].p) {
                                         ^280k   ^200k
  ------------------
  |  Branch (156:23): [True: 89.55%, False: 10.45%]
  |  Branch (156:28): [True: 71.26%, False: 28.74%]
  ------------------
  157|   200k|        maintain(u);
  158|   200k|      }
  159|   113k|    }
  160|   200k|  }
  161|   200k|  while (q--) {
  ------------------
  |  Branch (161:10): [True: 100.00%, False: 0.00%]
  ------------------
  162|   200k|    let t = rd.u1();
  163|   200k|    if (t == 0) {
  ------------------
  |  Branch (163:9): [True: 4.74%, False: 95.27%]
  ------------------
  164|  9.47k|      int u = node2id[rd.uh()];
  165|  9.47k|      node[u].v = {rd.uw(), rd.uw()};
  166|  66.3k|      for (; u; u = node[u].p) {
                              ^56.8k
  ------------------
  |  Branch (166:14): [True: 85.73%, False: 14.27%]
  ------------------
  167|  56.8k|        maintain(u);
  168|  56.8k|      }
  169|  9.47k|    }
  170|   200k|    if (t == 1) {
  ------------------
  |  Branch (170:9): [True: 95.27%, False: 4.74%]
  ------------------
  171|   190k|      int u = node2id[rd.uh()];
  172|   190k|      int v = node2id[rd.uh()];
  173|   190k|      u32 x = rd.uw();
  174|   190k|      Segment f = {1, 0, 0};
  175|  3.04M|      while (ances[u] != ances[v]) {
  ------------------
  |  Branch (175:14): [True: 93.75%, False: 6.25%]
  ------------------
  176|  2.85M|        if (depth[ances[u]] >= depth[ances[v]]) {
  ------------------
  |  Branch (176:13): [True: 50.00%, False: 50.00%]
  ------------------
  177|  1.42M|          x = apply(u, x);
  178|  1.42M|          u = parent[ances[u]];
  179|  1.42M|        } else {
  180|  1.42M|          f = apply(v, f);
  181|  1.42M|          v = parent[ances[v]];
  182|  1.42M|        }
  183|  2.85M|      }
  184|   190k|      if (u >= v) {
  ------------------
  |  Branch (184:11): [True: 49.91%, False: 50.09%]
  ------------------
  185|  95.1k|        x = apply(v, u, x);
  186|  95.4k|      } else {
  187|  95.4k|        f = apply(u, v, f);
  188|  95.4k|      }
  189|   190k|      x = x + f;
  190|   190k|      wt.uw(x);
  191|   190k|    }
  192|   200k|  }
  193|      1|  return 0;
  194|      1|}