/tmp/solutions/build/dynamic_tree_vertex_set_path_composite-main.cpp:
    1|       |#include <common.h>
    2|       |prelude;
    3|       |
    4|       |namespace {
    5|       |
    6|       |constexpr int N = 200001;
    7|       |constexpr u32 P = 998244353;
    8|       |
    9|       |struct Affine {
   10|       |  u32 a, b, c;
   11|  15.9M|  auto operator+(const Affine &t) const -> Affine {
   12|  15.9M|    u32 x = (u64(a) * t.a) % P;
   13|  15.9M|    u32 y = (u64(a) * t.b + b) % P;
   14|  15.9M|    u32 z = (u64(t.a) * c + t.c) % P;
   15|  15.9M|    return {x, y, z};
   16|  15.9M|  }
   17|   133k|  auto operator+(const u32 &t) const -> u32 { return (u64(a) * t + b) % P; }
   18|       |};
   19|       |struct Node {
   20|       |  u32 a;
   21|       |  u32 b;
   22|       |  Affine aff;
   23|       |  int p;
   24|       |  int ch[2];
   25|       |  i8 rev;
   26|       |  i8 k;
   27|       |} node[N];
   28|       |
   29|  10.3M|def reverse(int x) -> void {
   30|  10.3M|  node[x].rev ^= 1;
   31|  10.3M|  std::swap(node[x].aff.b, node[x].aff.c);
   32|  10.3M|}
   33|       |
   34|  12.1M|def pushdown(int x) -> void {
   35|  12.1M|  if (node[x].rev) {
  ------------------
  |  Branch (35:7): [True: 41.60%, False: 58.40%]
  ------------------
   36|  5.07M|    std::swap(node[x].ch[0], node[x].ch[1]);
   37|  5.07M|    node[node[x].ch[0]].k = 0;
   38|  5.07M|    node[node[x].ch[1]].k = 1;
   39|  5.07M|    reverse(node[x].ch[0]);
   40|  5.07M|    reverse(node[x].ch[1]);
   41|  5.07M|    node[x].rev = 0;
   42|  5.07M|  }
   43|  12.1M|}
   44|       |
   45|  7.96M|def maintain(int x) -> void {
   46|  7.96M|  node[x].aff = node[node[x].ch[0]].aff +
   47|  7.96M|                Affine{node[x].a, node[x].b, node[x].b} +
   48|  7.96M|                node[node[x].ch[1]].aff;
   49|  7.96M|}
   50|       |
   51|  7.96M|def rotateup(int x) -> void {
   52|  7.96M|  int p = node[x].p;
   53|  7.96M|  int g = node[p].p;
   54|  7.96M|  int k = node[x].k;
   55|  7.96M|  int t = node[p].k;
   56|  7.96M|  node[node[x].ch[k ^ 1]].p = p;
   57|  7.96M|  node[node[x].ch[k ^ 1]].k = k;
   58|  7.96M|  node[p].ch[k] = node[x].ch[k ^ 1];
   59|  7.96M|  node[p].p = x;
   60|  7.96M|  node[p].k = k ^ 1;
   61|  7.96M|  node[x].ch[k ^ 1] = p;
   62|  7.96M|  node[x].p = g;
   63|  7.96M|  node[x].k = t;
   64|  7.96M|  if (t != -1) {
  ------------------
  |  Branch (64:7): [True: 85.60%, False: 14.40%]
  ------------------
   65|  6.82M|    node[g].ch[t] = x;
   66|  6.82M|  }
   67|  7.96M|  maintain(p);
   68|  7.96M|}
   69|       |
   70|  8.64M|def is_root(int x) -> bool { return node[x].k == -1; }
   71|       |
   72|  1.00M|def splay(int x) -> void {
   73|  1.00M|  pushdown(x);
   74|  4.82M|  while (!is_root(x)) {
  ------------------
  |  Branch (74:10): [True: 79.26%, False: 20.74%]
  ------------------
   75|  3.82M|    if (int p = node[x].p; is_root(p)) {
  ------------------
  |  Branch (75:28): [True: 7.25%, False: 92.75%]
  ------------------
   76|   277k|      pushdown(p);
   77|   277k|      pushdown(x);
   78|   277k|      rotateup(x);
   79|  3.54M|    } else {
   80|  3.54M|      int g = node[p].p;
   81|  3.54M|      pushdown(g);
   82|  3.54M|      pushdown(p);
   83|  3.54M|      pushdown(x);
   84|  3.54M|      if (node[x].k == node[p].k) {
  ------------------
  |  Branch (84:11): [True: 55.89%, False: 44.11%]
  ------------------
   85|  1.98M|        rotateup(p);
   86|  1.98M|        rotateup(x);
   87|  1.98M|      } else {
   88|  1.56M|        rotateup(x);
   89|  1.56M|        rotateup(x);
   90|  1.56M|      }
   91|  3.54M|    }
   92|  3.82M|  }
   93|  1.00M|}
   94|       |
   95|   333k|def access(int x) -> void {
   96|   333k|  splay(x);
   97|   333k|  node[node[x].ch[1]].k = -1;
   98|   333k|  node[x].ch[1] = 0;
   99|   933k|  while (int p = node[x].p) {
  ------------------
  |  Branch (99:14): [True: 64.29%, False: 35.71%]
  ------------------
  100|   600k|    splay(p);
  101|   600k|    node[node[p].ch[1]].k = -1;
  102|   600k|    node[p].ch[1] = x;
  103|   600k|    node[x].k = 1;
  104|   600k|    rotateup(x);
  105|   600k|  }
  106|   333k|}
  107|       |
  108|       |int head[N];
  109|       |struct {
  110|       |  int to;
  111|       |  int next;
  112|       |} edge[N * 2];
  113|       |
  114|   200k|def build(int u, int p) -> void {
  115|   599k|  for (int e = head[u]; e; e = edge[e].next) {
                                         ^399k
  ------------------
  |  Branch (115:25): [True: 66.67%, False: 33.33%]
  ------------------
  116|   399k|    int v = edge[e].to;
  117|   399k|    if (v != p) {
  ------------------
  |  Branch (117:9): [True: 50.00%, False: 50.00%]
  ------------------
  118|   199k|      build(v, u);
  119|   199k|      node[v + 1].p = u + 1;
  120|   199k|    }
  121|   399k|  }
  122|   200k|}
  123|       |
  124|       |} // namespace
  125|       |
  126|      1|int main() {
  127|      1|  node[0].aff.a = 1;
  128|      1|  rd rd;
  129|      1|  wt wt;
  130|      1|  int n = rd.uh();
  131|      1|  int q = rd.uh();
  132|      1|#ifdef LOCAL
  133|      1|  std::memset(head, 0, 4 * n);
  134|      1|#endif
  135|   200k|  for (int i = 1; i <= n; ++i) {
                                        ^200k
  ------------------
  |  Branch (135:19): [True: 100.00%, False: 0.00%]
  ------------------
  136|   200k|    node[i] = {.k = -1};
  137|   200k|    u32 a = node[i].a = rd.uw();
  138|   200k|    u32 b = node[i].b = rd.uw();
  139|   200k|    node[i].aff = {a, b, b};
  140|   200k|  }
  141|   200k|  for (int i = 1; i != n; ++i) {
                                        ^199k
  ------------------
  |  Branch (141:19): [True: 100.00%, False: 0.00%]
  ------------------
  142|   199k|    int u = rd.uh();
  143|   199k|    int v = rd.uh();
  144|   199k|    edge[i * 2 | 0] = {v, head[u]}, head[u] = i * 2 | 0;
  145|   199k|    edge[i * 2 | 1] = {u, head[v]}, head[v] = i * 2 | 1;
  146|   199k|  }
  147|      1|  build(0, 0);
  148|   200k|  while (q--) {
  ------------------
  |  Branch (148:10): [True: 100.00%, False: 0.00%]
  ------------------
  149|   200k|    let t = rd.u1();
  150|   200k|    if (t == 0) {
  ------------------
  |  Branch (150:9): [True: 33.37%, False: 66.63%]
  ------------------
  151|  66.7k|      int u = rd.uh() + 1;
  152|  66.7k|      int v = rd.uh() + 1;
  153|  66.7k|      access(u);
  154|  66.7k|      reverse(u);
  155|  66.7k|      access(v);
  156|  66.7k|      node[node[v].ch[0]].p = 0;
  157|  66.7k|      node[node[v].ch[0]].k = -1;
  158|  66.7k|      node[v].ch[0] = 0;
  159|  66.7k|      int w = rd.uh() + 1;
  160|  66.7k|      int x = rd.uh() + 1;
  161|  66.7k|      access(w);
  162|  66.7k|      reverse(w);
  163|  66.7k|      node[w].p = x;
  164|  66.7k|    }
  165|   200k|    if (t == 1) {
  ------------------
  |  Branch (165:9): [True: 33.33%, False: 66.67%]
  ------------------
  166|  66.6k|      int u = rd.uh() + 1;
  167|  66.6k|      node[u].a = rd.uw();
  168|  66.6k|      node[u].b = rd.uw();
  169|  66.6k|      splay(u);
  170|  66.6k|    }
  171|   200k|    if (t == 2) {
  ------------------
  |  Branch (171:9): [True: 33.30%, False: 66.70%]
  ------------------
  172|  66.5k|      int u = rd.uh() + 1;
  173|  66.5k|      int v = rd.uh() + 1;
  174|  66.5k|      u32 x = rd.uw();
  175|  66.5k|      access(v);
  176|  66.5k|      reverse(v);
  177|  66.5k|      access(u);
  178|  66.5k|      x = Affine{node[u].a, node[u].b, node[u].b} + x;
  179|  66.5k|      x = node[node[u].ch[0]].aff + x;
  180|  66.5k|      wt.ud(x);
  181|  66.5k|    }
  182|   200k|  }
  183|      1|  return 0;
  184|      1|}