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
| #include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5,P = 998244353,inv2 = (P + 1) / 2; inline void Plus(int &x,const int &y) { x += y;if(x >= P) x -= P;} inline int qpow(int a,int b) { int res = 1;while(b) { if(b&1) res = 1ll * res * a % P;a = 1ll * a * a % P;b >>= 1;} return res;} int n,m; int Pow2[N],Powi2[N]; int f[N],g[N],tim[N]; inline void Giv(int x,int v) { g[x] = (1ll * (g[x] - 1 + P) * Powi2[v] % P + 1) % P;tim[x] += v;} inline void pushdown(int x) { if(tim[x]) Giv(x << 1,tim[x]),Giv(x << 1 | 1,tim[x]),tim[x] = 0; } int Sum; inline void modify(int k,int l,int r,int x,int y) { if(x <= l && r <= y) { Plus(Sum,P - f[k]); f[k] = 1ll * (f[k] + 1) * inv2 % P; g[k] = 1ll * (g[k] + 1) * inv2 % P; Plus(Sum,f[k]); if(l != r) { Giv(k << 1,1);Giv(k << 1 | 1,1); } return; } pushdown(k);
int mid = l + r >> 1; Plus(Sum,P - f[k]); f[k] = 1ll * f[k] * inv2 % P; g[k] = 1ll * g[k] * inv2 % P; Plus(Sum,f[k]); if(x <= mid) modify(k << 1,l,mid,x,y); else { Plus(Sum,P - f[k << 1]); f[k << 1] = 1ll * (f[k << 1] + g[k << 1]) * inv2 % P; Plus(Sum,f[k << 1]); } if(mid < y) modify(k << 1 | 1,mid + 1,r,x,y); else { Plus(Sum,P - f[k << 1 | 1]); f[k << 1 | 1] = 1ll * (f[k << 1 | 1] + g[k << 1 | 1]) * inv2 % P; Plus(Sum,f[k << 1 | 1]); } } int main() { cin >> n >> m; Pow2[0] = Powi2[0] = 1; for(int i = 1;i <= m;i++) Pow2[i] = 2ll * Pow2[i - 1] % P,Powi2[i] = 1ll * inv2 * Powi2[i - 1] % P; Sum = 0; for(int i = 1,ct = 0;i <= m;i++) { int op,l,r; cin >> op; if(op == 2) cout << 1ll * Sum * Pow2[ct] % P << endl; else cin >> l >> r,++ct,modify(1,1,n,l,r);
} return 0; }
|