1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| #include <bits/stdc++.h>
using namespace std; const int N = 2e5 + 10, mod = 20130426, INF = 1 << 30; struct node { int s[2], v, p, sz, mul, add; void init(int _v, int _p) { s[0] = s[1] = 0, v = _v, p = _p, mul = sz = 1; } } t[N]; int root, tot; int res, now;
inline int read() { int x = 0, y = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') y = -1; c = getchar();} while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * y; }
inline void pushup(int x) { t[x].sz = t[t[x].s[0]].sz + t[t[x].s[1]].sz + 1; }
inline void pushadd(int x, int v) { t[x].add = (t[x].add + v) % mod, t[x].v = (t[x].v + v) % mod; }
inline void pushmul(int x, int v) { t[x].mul = 1ll * t[x].mul * v % mod, t[x].add = 1ll * t[x].add * v % mod, t[x].v = 1ll * t[x].v * v % mod; }
inline void pushdown(int x) { pushmul(t[x].s[0], t[x].mul), pushmul(t[x].s[1], t[x].mul), t[x].mul = 1; pushadd(t[x].s[0], t[x].add), pushadd(t[x].s[1], t[x].add), t[x].add = 0; }
inline void rotate(int x) { int y = t[x].p, z = t[y].p, k = t[y].s[1] == x; t[z].s[t[z].s[1] == y] = x, t[x].p = z; t[y].s[k] = t[x].s[!k], t[t[x].s[!k]].p = y; t[x].s[!k] = y, t[y].p = x; pushup(y), pushup(x); }
inline void splay(int x, int k) { while (t[x].p != k) { int y = t[x].p, z = t[y].p; if (z != k) if ((t[z].s[1] == y) ^ (t[y].s[1] == x)) rotate(x); else rotate(y); rotate(x); } if (!k) root = x; }
inline int get_k(int k) { int u = root; while (u) { pushdown(u); if (t[t[u].s[0]].sz >= k) u = t[u].s[0]; else if (t[t[u].s[0]].sz + 1 == k) return u; else k -= t[t[u].s[0]].sz + 1, u = t[u].s[1]; } return u; }
inline int build(int l, int r, int p) { int mid = (l + r) >> 1; int u = ++tot; t[u].init(0, p); if (l < mid) t[u].s[0] = build(l, mid - 1, u); if (r > mid) t[u].s[1] = build(mid + 1, r, u); return pushup(u), u; }
inline void query(int u, int v) { pushdown(u); if (t[u].s[0]) query(t[u].s[0], v); if (now != -1) res = (res + 1ll * t[u].v * now % mod) % mod, now = 1ll * now * v % mod; else now = 1; if (t[u].s[1]) query(t[u].s[1], v); }
int main() { int q = read(); root = build(0, 1e5 + 2, 0); while (q--) { string op; cin >> op; if (op == "mul") { int l = read() + 1, r = read() + 1, v = read(); l = get_k(l), r = get_k(r + 2); splay(l, 0), splay(r, l); node &son = t[t[r].s[0]]; son.v = 1ll * son.v * v % mod, son.mul = 1ll * son.mul * v % mod, son.add = 1ll * son.add * v % mod; } else if (op == "add") { int l = read() + 1, r = read() + 1, v = read(); l = get_k(l), r = get_k(r + 2); splay(l, 0), splay(r, l); node &son = t[t[r].s[0]]; son.v = (son.v + v) % mod, son.add = (son.add + v) % mod; } else if (op == "mulx") { int l = read() + 1, r = read() + 1; int lp = get_k(r), rp = get_k(r + 2); splay(lp, 0), splay(rp, lp); int k = t[t[rp].s[0]].v; t[rp].v += k; t[rp].s[0] = 0, pushup(rp), pushup(lp); lp = get_k(l), rp = get_k(l + 1); splay(lp, 0), splay(rp, lp); int u = ++tot; t[u].init(0, rp), t[rp].s[0] = u; pushup(rp), pushup(lp); } else { int v = read(); printf("%d\n", (res = 0, now = -1, query(root, v), res)); } } return 0; }
|