```cpp
void upda1(LL l, LL r, LL d, LL cl = 1, LL cr = n, LL p = 1)
{
if(l > cr || r < cl) return;
else if(cl >= l && cr <= r)
{
tree[p].val = (tree[p].val * d) % m;
tree[p].mul = (tree[p].mul * d) % m;
tree[p].add = (tree[p].add * d) % m;
}
else
{
LL mid = (cl + cr) / 2;
push_down(p,cl, cr);
upda1(l,r,d,cl,mid,p * 2);
upda1(l,r,d,mid + 1,cr,p * 2 + 1);
tree[p].val = (tree[p * 2].val + tree[p * 2 + 1].val) % m;
}
}
void upda2(LL l,LL r,LL d,LL cl = 1,LL cr = n,LL p = 1)
{
if(l > cr || r < cl) return;
else if(cl >= l && cr <= r)
{
tree[p].val = (tree[p].val + d * (cr - cl + 1)) % m;
tree[p].add = (tree[p].add + d) % m;
}
else
{
LL mid = (cr + cl) / 2;
push_down(p,cl, cr);
upda2(l,r,d,cl,mid,p * 2);
upda2(l,r,d,mid + 1,cr,p * 2 + 1);
tree[p].val = (tree[p * 2].val + tree[p * 2 + 1].val) % m;
}
}
```
两个函数改成这样,你的问题可能在于,在你的可修改区间里面,你的懒标记修改判断的大于小于号写反了
所以这样也是可以的
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL n,q,m,a[N];
struct Node{
LL val,mul,add;
}tree[N * 4];
void build(LL l = 1, LL r = n, LL p = 1)
{
tree[p].add = 0;
tree[p].mul = 1;
if(l == r)
{
tree[p].val = a[l];
}
else
{
LL mid = (l + r) / 2;
build(l, mid, p * 2);
build(mid + 1, r, p * 2 + 1);
tree[p].val = (tree[p * 2].val + tree[p * 2 + 1].val) % m;
}
tree[p].val %= m;
}
void push_down(LL p,LL l, LL r)
{
int mid = l + r >> 1;
int len1 = mid - l + 1, len2 = r - mid;
tree[p * 2].val = (tree[p * 2].val * tree[p].mul + tree[p].add * len1) % m;
tree[p * 2 + 1].val = (tree[p * 2 + 1].val * tree[p].mul + tree[p].add * len2) % m;
tree[p * 2].mul = (tree[p * 2].mul * tree[p].mul) % m;
tree[p * 2 + 1].mul = (tree[p * 2 + 1].mul * tree[p].mul) % m;
tree[p * 2].add = (tree[p * 2].add * tree[p].mul + tree[p].add) % m;
tree[p * 2 + 1].add = (tree[p * 2 + 1].add * tree[p].mul + tree[p].add) % m;
tree[p].mul = 1;
tree[p].add = 0;
}
void upda1(LL l, LL r, LL d, LL cl = 1, LL cr = n, LL p = 1)
{
if(l > cr || r < cl) return;
else if(cl >= l && cr <= r)
{
tree[p].val = (tree[p].val * d) % m;
if(cl < cr)
{
tree[p].mul = (tree[p].mul * d) % m;
tree[p].add = (tree[p].add * d) % m;
}
}
else
{
LL mid = (cl + cr) / 2;
push_down(p,cl, cr);
upda1(l,r,d,cl,mid,p * 2);
upda1(l,r,d,mid + 1,cr,p * 2 + 1);
tree[p].val = (tree[p * 2].val + tree[p * 2 + 1].val) % m;
}
}
void upda2(LL l,LL r,LL d,LL cl = 1,LL cr = n,LL p = 1)
{
if(l > cr || r < cl) return;
else if(cl >= l && cr <= r)
{
tree[p].val = (tree[p].val + d * (cr - cl + 1)) % m;
if(cl < cr) tree[p].add = (tree[p].add + d) % m;
}
else
{
LL mid = (cr + cl) / 2;
push_down(p,cl, cr);
upda2(l,r,d,cl,mid,p * 2);
upda2(l,r,d,mid + 1,cr,p * 2 + 1);
tree[p].val = (tree[p * 2].val + tree[p * 2 + 1].val) % m;
}
}
LL query(LL l,LL r,LL cl = 1,LL cr = n, LL p = 1)
{
if(l > cr || r < cl) return 0;
else if(cl >= l && cr <= r)
{
return tree[p].val;
}
else
{
LL mid = (cl + cr) / 2;
push_down(p,cl, cr);
return (query(l,r,cl,mid,p * 2) + query(l,r,mid + 1,cr,p * 2 + 1)) % m;
}
}
int main()
{
cin>>n>>q>>m;
for(int i = 1; i <= n; i++) cin>>a[i];
build();
while(q--)
{
int op;
LL l,r,k;
cin>>op;
if(op == 1)
{
cin>>l>>r>>k;
upda1(l,r,k);
}
else if(op == 2)
{
cin>>l>>r>>k;
upda2(l,r,k);
}
else
{
cin>>l>>r;
LL ans = query(l,r);
cout<<ans<<endl;
}
}
}
```
by 烨雨 @ 2023-08-04 18:51:49
@[烨雨](/user/77288) 我靠!看见了,写成cl>cr了
by Wild468 @ 2023-08-04 19:48:50
牛啊牛啊
by 烨雨 @ 2023-08-31 23:12:12