/tmp/solutions/build/dynamic_sequence_range_affine_range_sum-main.cpp:
    1|       |#include <common.h>
    2|       |prelude;
    3|       |
    4|       |namespace {
    5|       |
    6|       |constexpr int N = 1000003;
    7|       |constexpr u32 P = 998244353;
    8|       |
    9|       |struct Node {
   10|       |  u32 val;
   11|       |  u32 sum;
   12|       |  u32 a;
   13|       |  u32 b;
   14|       |  int rev;
   15|       |  int size;
   16|       |  int l, r;
   17|       |} node[N];
   18|       |
   19|  22.4M|def maintain(int x) -> void {
   20|  22.4M|  node[x].size = node[node[x].l].size + 1 + node[node[x].r].size;
   21|  22.4M|  node[x].sum = (node[node[x].l].sum + node[x].val + node[node[x].r].sum) % P;
   22|  22.4M|}
   23|       |
   24|   998k|def build(int l, int r) -> int {
   25|   998k|  if (l > r) return 0;
                           ^499k
  ------------------
  |  Branch (25:7): [True: 50.00%, False: 50.00%]
  ------------------
   26|   499k|  int m = (l + r) / 2;
   27|   499k|  node[m].l = build(l, m - 1);
   28|   499k|  node[m].r = build(m + 1, r);
   29|   499k|  maintain(m);
   30|   499k|  return m;
   31|   998k|}
   32|       |
   33|   100k|def reverse(int x) -> void { node[x].rev ^= 1; }
   34|       |
   35|  29.6M|def affine(int x, u64 a, u64 b) -> void {
   36|  29.6M|  if (x == 0) return;
                            ^2.25M
  ------------------
  |  Branch (36:7): [True: 7.60%, False: 92.40%]
  ------------------
   37|  27.4M|  node[x].a = (a * node[x].a) % P;
   38|  27.4M|  node[x].b = (a * node[x].b + b) % P;
   39|  27.4M|  node[x].val = (a * node[x].val + b) % P;
   40|  27.4M|  node[x].sum = (a * node[x].sum + b * node[x].size) % P;
   41|  27.4M|}
   42|       |
   43|  22.9M|def pushdown(int x) -> void {
   44|  22.9M|  if (node[x].rev) {
  ------------------
  |  Branch (44:7): [True: 34.80%, False: 65.20%]
  ------------------
   45|  7.97M|    std::swap(node[x].l, node[x].r);
   46|  7.97M|    node[node[x].l].rev ^= 1;
   47|  7.97M|    node[node[x].r].rev ^= 1;
   48|  7.97M|    node[x].rev = 0;
   49|  7.97M|  }
   50|  22.9M|  if ((node[x].a != 1) | (node[x].b != 0)) {
  ------------------
  |  Branch (50:7): [True: 64.46%, False: 35.54%]
  ------------------
   51|  14.7M|    affine(node[x].l, node[x].a, node[x].b);
   52|  14.7M|    affine(node[x].r, node[x].a, node[x].b);
   53|  14.7M|    node[x].a = 1;
   54|  14.7M|    node[x].b = 0;
   55|  14.7M|  }
   56|  22.9M|}
   57|       |
   58|  11.6M|def zig(int &x) -> void {
   59|  11.6M|  int l = node[x].l;
   60|  11.6M|  node[x].l = node[l].r;
   61|  11.6M|  maintain(x);
   62|  11.6M|  node[l].r = x;
   63|  11.6M|  x = l;
   64|  11.6M|}
   65|       |
   66|  10.2M|def zag(int &x) -> void {
   67|  10.2M|  int r = node[x].r;
   68|  10.2M|  node[x].r = node[r].l;
   69|  10.2M|  maintain(x);
   70|  10.2M|  node[r].l = x;
   71|  10.2M|  x = r;
   72|  10.2M|}
   73|       |
   74|  11.7M|def splay(int &x, int k) -> void {
   75|  11.7M|  pushdown(x);
   76|  11.7M|  if (int &l = node[x].l, &r = node[x].r, size = node[l].size; k == size) {
  ------------------
  |  Branch (76:64): [True: 4.25%, False: 95.75%]
  ------------------
   77|   498k|    return;
   78|  11.2M|  } else if (k < size) {
  ------------------
  |  Branch (78:14): [True: 53.28%, False: 46.72%]
  ------------------
   79|  5.97M|    pushdown(l);
   80|  5.97M|    if (int &ll = node[l].l, &lr = node[l].r, size = node[ll].size; k == size) {
  ------------------
  |  Branch (80:69): [True: 4.83%, False: 95.17%]
  ------------------
   81|   288k|      zig(x);
   82|  5.68M|    } else if (k < size) {
  ------------------
  |  Branch (82:16): [True: 58.05%, False: 41.95%]
  ------------------
   83|  3.30M|      splay(ll, k);
   84|  3.30M|      zig(x);
   85|  3.30M|      zig(x);
   86|  3.30M|    } else {
   87|  2.38M|      splay(lr, k - size - 1);
   88|  2.38M|      zag(l);
   89|  2.38M|      zig(x);
   90|  2.38M|    }
   91|  5.97M|  } else {
   92|  5.23M|    pushdown(r);
   93|  5.23M|    k -= size + 1;
   94|  5.23M|    if (int &rl = node[r].l, &rr = node[r].r, size = node[rl].size; k == size) {
  ------------------
  |  Branch (94:69): [True: 4.04%, False: 95.96%]
  ------------------
   95|   211k|      zag(x);
   96|  5.02M|    } else if (k < size) {
  ------------------
  |  Branch (96:16): [True: 47.74%, False: 52.26%]
  ------------------
   97|  2.39M|      splay(rl, k);
   98|  2.39M|      zig(r);
   99|  2.39M|      zag(x);
  100|  2.62M|    } else {
  101|  2.62M|      splay(rr, k - size - 1);
  102|  2.62M|      zag(x);
  103|  2.62M|      zag(x);
  104|  2.62M|    }
  105|  5.23M|  }
  106|  11.7M|}
  107|       |
  108|       |} // namespace
  109|       |
  110|      1|int main() {
  111|      1|  rd rd;
  112|      1|  wt wt;
  113|      1|  int n = rd.uh();
  114|      1|  int q = rd.uh();
  115|   998k|  for (int i = 1; i <= n + q + 1; ++i) node[i] = Node{.a = 1, .size = 1};
                                                ^998k^998k
  ------------------
  |  Branch (115:19): [True: 100.00%, False: 0.00%]
  ------------------
  116|   499k|  for (int i = 2; i <= n + 1; ++i) node[i].val = rd.uw();
                                            ^499k^499k
  ------------------
  |  Branch (116:19): [True: 100.00%, False: 0.00%]
  ------------------
  117|      1|  int x = build(1, n += 2);
  118|   499k|  while (q--) {
  ------------------
  |  Branch (118:10): [True: 100.00%, False: 0.00%]
  ------------------
  119|   499k|    let t = rd.u1();
  120|   499k|    if (t == 0) {
  ------------------
  |  Branch (120:9): [True: 20.06%, False: 79.94%]
  ------------------
  121|   100k|      ++n;
  122|   100k|      int k = rd.uh();
  123|   100k|      node[n].val = node[n].sum = rd.uw();
  124|   100k|      splay(x, k);
  125|   100k|      splay(node[x].r, 0);
  126|   100k|      node[node[x].r].l = n;
  127|   100k|    }
  128|   499k|    if (t == 1) {
  ------------------
  |  Branch (128:9): [True: 19.89%, False: 80.11%]
  ------------------
  129|  99.3k|      int k = rd.uh();
  130|  99.3k|      splay(x, k);
  131|  99.3k|      splay(node[x].r, 1);
  132|  99.3k|      node[node[x].r].l = 0;
  133|  99.3k|    }
  134|   499k|    if (t == 2) {
  ------------------
  |  Branch (134:9): [True: 20.08%, False: 79.92%]
  ------------------
  135|   100k|      int l = rd.uh();
  136|   100k|      int r = rd.uh();
  137|   100k|      splay(x, l);
  138|   100k|      splay(node[x].r, r - l);
  139|   100k|      reverse(node[node[x].r].l);
  140|   100k|    }
  141|   499k|    if (t == 3) {
  ------------------
  |  Branch (141:9): [True: 20.00%, False: 80.00%]
  ------------------
  142|  99.8k|      int l = rd.uh();
  143|  99.8k|      int r = rd.uh();
  144|  99.8k|      splay(x, l);
  145|  99.8k|      splay(node[x].r, r - l);
  146|  99.8k|      int a = rd.uw();
  147|  99.8k|      int b = rd.uw();
  148|  99.8k|      affine(node[node[x].r].l, a, b);
  149|  99.8k|    }
  150|   499k|    if (t == 4) {
  ------------------
  |  Branch (150:9): [True: 19.97%, False: 80.03%]
  ------------------
  151|  99.7k|      int l = rd.uh();
  152|  99.7k|      int r = rd.uh();
  153|  99.7k|      splay(x, l);
  154|  99.7k|      splay(node[x].r, r - l);
  155|  99.7k|      wt.ud(node[node[node[x].r].l].sum);
  156|  99.7k|    }
  157|   499k|  }
  158|      1|  return 0;
  159|      1|}