模板题调炸了,求大佬
#include<bits/stdc++.h>
#define debug cout << "OK" << endl;
#define MAXN int(1e5 + 10)
#define MAXM int(1e5 + 10)
#define Mod 571373
using namespace std;
long long a[MAXN], n, m;
int tree[MAXN << 2], mark_mul[MAXN << 2], mark_add[MAXN << 2];
inline int lson(const int &rt)
{
return rt << 1;
}
inline int rson(const int &rt)
{
return rt << 1 | 1;
}
inline void push_up_sum(const int &rt)
{
tree[rt] = (tree[lson(rt)] + tree[rson(rt)]) % Mod;
}
inline void push_down(const int &rt, const int &len)
{
tree[lson(rt)] = (tree[lson(rt)] * mark_mul[rt] + mark_add[rt] * (len - len / 2)) % Mod;
tree[rson(rt)] = (tree[rson(rt)] * mark_mul[rt] + mark_add[rt] * len / 2) % Mod;
mark_mul[lson(rt)] = (mark_mul[lson(rt)] * mark_mul[rt]) % Mod;
mark_mul[rson(rt)] = (mark_mul[rson(rt)] * mark_mul[rt]) % Mod;
mark_add[lson(rt)] = (mark_add[lson(rt)] * mark_mul[rt] + mark_add[rt]) % Mod;
mark_add[rson(rt)] = (mark_add[rson(rt)] * mark_mul[rt] + mark_add[rt]) % Mod;
mark_mul[rt] = 1;
mark_add[rt] = 0;
}
inline void build(const int &rt, const int &l, const int &r)
{
mark_mul[rt] = 1;
if(l == r)
{
tree[rt] = a[l] % Mod;
return ;
}
build(lson(rt), l, (l + r) >> 1);
build(rson(rt), ((l + r) >> 1) + 1, r);
push_up_sum(rt);
}
inline void update_mul(const int &l, const int &r, const int &rt, const int &cl, const int &cr, const long long& d)
{
if(l > cr || r < cl)
{
return ;
}
else if(l >= cl && r <= cr)
{
tree[rt] = (tree[rt] * d) % Mod;
mark_mul[rt] = (mark_mul[rt] * d) % Mod;
mark_add[rt] = (mark_add[rt] * d) % Mod;
return ;
}
else
{
push_down(rt, r - l + 1);
update_mul(l, (l + r) >> 1, lson(rt), cl, cr, d);
update_mul(((l + r) >> 1) + 1, r, rson(rt), cl, cr, d);
push_up_sum(rt);
return ;
}
}
inline void update_add(const int &l, const int &r, const int &rt, const int &cl, const int &cr, const long long &d)
{
if(l > cr || r < cl)
{
return ;
}
else if(l >= cl && r <= cr)
{
tree[rt] = (tree[rt] + d * (r - l + 1)) % Mod;
mark_add[rt] = (mark_add[rt] + d) % Mod;
return ;
}
else
{
push_down(rt, r - l + 1);
update_add(l, (l + r) >> 1, lson(rt), cl, cr, d);
update_add(((l + r) >> 1) + 1, r, rson(rt), cl, cr, d);
push_up_sum(rt);
return ;
}
}
inline int query(const int &l, const int &r, const int &rt, const int &cl, const int &cr)
{
if(l > cr || r < cl)
{
return 0;
}
else if(l >= cl && r <= cr)
{
return tree[rt];
}
else
{
push_down(rt, r - l + 1);
return (query(l, (l + r) >> 1, lson(rt), cl, cr) + query(((l + r) >> 1) + 1, r, rson(rt), cl, cr)) % Mod;
}
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
scanf("%lld", &a[i]);
}
build(1, 1, n);
while(m--)
{
long long opr, l, r, x;
scanf("%lld %lld %lld", &opr, &l, &r);
if(opr == 1)
{
scanf("%lld", &x);
update_mul(1, n, 1, l, r, x);
}
else if(opr == 2)
{
scanf("%lld", &x);
update_add(1, n, 1, l, r, x);
}
else
{
printf("%d\n", query(1, n, 1, l, r));
}
}
return 0;
}