【代码】LC: 点赋值区间复合(Point Set Range Composite)

📅 2026/8/9 20:17:25
【代码】LC: 点赋值区间复合(Point Set Range Composite)
这题挺有意思的放个代码#includebits/stdc.h using namespace std; typedef long long LL; #define lc(p) (p 1) #define rc(p) ((p 1) | 1) const LL P 998244353; const int N 5e5 10; LL A[N], B[N]; struct node { int l, r; LL a, b; } tr[N 2]; void pushup(int p) { tr[p].a tr[rc(p)].a * tr[lc(p)].a % P; tr[p].b (tr[rc(p)].a * tr[lc(p)].b % P tr[rc(p)].b) % P; // ra(la * x lb) rb // ra * la * x ra * lb rb } void build(int p, int l, int r) { tr[p] {l, r, 0, 0}; if (l r) { tr[p].a A[l]; tr[p].b B[l]; return ; } int mid (l r) 1; build(lc(p), l, mid); build(rc(p), mid 1, r); pushup(p); } void change(int p, int x, int c, int d) { if (x tr[p].l || tr[p].r x) { return ; } if (tr[p].l tr[p].r) { tr[p].a c; tr[p].b d; return ; } change(lc(p), x, c, d); change(rc(p), x, c, d); pushup(p); } node query(int p, int l, int r) { if (r tr[p].l || tr[p].r l) { return {0, 0, 1, 0}; } if (l tr[p].l tr[p].r r) { return tr[p]; } node nl query(lc(p), l, r); node nr query(rc(p), l, r); node no {0, 0, nr.a * nl.a % P, (nr.a * nl.b % P nr.b) % P}; // ra(la * x lb) rb // ra * la * x ra * lb rb return no; } int main () { ios::sync_with_stdio(false); cin.tie(0); int n, Q; cin n Q; for (int i 1; i n; i ) { cin A[i] B[i]; } build(1, 1, n); while (Q --) { int opt; cin opt; if (opt 0) { int x; LL c, d; cin x c d; x ; change(1, x, c, d); } else { int l, r; LL x; cin l r x; l ; node ans query(1, l, r); cout (ans.a * x % P ans.b) % P \n; } } return 0; }