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 124 125 126 127 128 129 130 131 132 133 134 135
| #include <bits/stdc++.h> #define int __int128 #define gh() getchar() using namespace std; const int N = 1e5 + 5, P = 998244353; int n, m; int a[N]; struct LineTree { int l, r; int v, s2, sl2, sm; int add; #define l(x) tr[(x)].l #define r(x) tr[(x)].r #define v(x) tr[(x)].v #define s2(x) tr[(x)].s2 #define sl2(x) tr[(x)].sl2 #define sm(x) tr[(x)].sm #define ad(x) tr[(x)].add #define lc (u << 1) #define rc (u << 1 | 1) #define Mid (tr[u].l + tr[u].r >> 1) } tr[N << 2]; void read(int &x) { x = 0; char ch = gh(), t = 0; while (ch < '0' || ch > '9') t |= ch == '-', ch = gh(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = gh(); if (t) x = -x; } void write(int x) { if (x > 9) write(x / 10); putchar(x % 10 + '0'); } int qpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = res * x % P; x = x * x % P; y >>= 1; } return res; } void push_init(int u) { int len = r(u) - l(u) + 1; v(u) = (v(lc) + v(rc)); s2(u) = (v(u) * v(u) + s2(lc) + s2(rc)); sl2(u) = (len * len + sl2(lc) + sl2(rc)); sm(u) = ((r(u) - l(u) + 1) * v(u)+ sm(lc) + sm(rc)); } void push_up(int u) { v(u) = (v(lc) + v(rc)); s2(u) = (v(u) * v(u) + s2(lc) + s2(rc)); sm(u) = ((r(u) - l(u) + 1) * v(u) + sm(lc) + sm(rc)); } void add_tag(int u, int d) { s2(u) = (sl2(u) * d * d +d * 2 * sm(u) + s2(u)); v(u) = ((r(u) - l(u) + 1) * d + v(u)); sm(u) = (sl2(u) * d + sm(u)); ad(u) = (ad(u) + d); } void push_down(int u) { if (ad(u)) { add_tag(lc, ad(u)); add_tag(rc, ad(u)); ad(u) = 0; } } void build(int u, int l, int r) { l(u) = l, r(u) = r; if (l == r) { v(u) = sm(u) = a[l]; s2(u) = a[l] * a[l]; sl2(u) = 1; return ; } int mid = Mid; build(lc, l, mid), build(rc, mid + 1, r); push_init(u); } void modify(int u, int l, int r, int d) { if (l(u) >= l && r(u) <= r) return add_tag(u, d); push_down(u); int mid = Mid; if (l <= mid) modify(lc, l, r, d); if (r > mid) modify(rc, l, r, d); push_up(u); } int ask() { int t = __gcd(s2(1), v(1)); int A = s2(1) / t, B = v(1) / t; return A % P * qpow(B, P - 2) % P; } signed main() { read(n), read(m); for (int i = 1; i <= n; ++i) read(a[i]); build(1, 1, n); int op, l, r, v; while (m--) { read(op); if (op == 1) { read(l), read(r), read(v); modify(1, l, r, v); } else write(ask()), putchar('\n'); } return 0; }
|