洛谷全WA,在线工具报了RE,看了半天没看出来哪里细节出错了,大佬求调QAQ
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,q,a[100005];
struct node{
ll v,l,r,tt,pt;
}t[500006];
void est(ll p,ll l,ll r){
t[p].l=l,t[p].r=r,t[p].tt=1,t[p].pt=0;
if(l==r){t[p].v=a[l]%m;return;}
ll mid=(l+r)/2;
est(p*2,l,mid);
est(p*2+1,mid+1,r);
t[p].v=(t[p*2].v+t[p*2+1].v)%m;
return;
}
void lazy(ll p){
t[p*2].v=(t[p].tt*t[p*2].v+((t[p*2].r-t[p*2].l+1)*t[p].pt)%m)%m;
t[p*2+1].v=(t[p].tt*t[p*2+1].v+((t[p*2+1].r-t[p*2+1].l+1)*t[p].pt)%m)%m;
t[p*2].pt=(t[p].pt+t[p*2].pt*t[p].tt)%m;
t[p*2+1].pt=(t[p].pt+t[p*2+1].pt*t[p].tt)%m;
t[p*2].tt=(t[p].tt*t[p*2].tt)%m;
t[p*2+1].tt=(t[p].tt*t[p*2+1].tt)%m;
t[p].pt=0,t[p].tt=1;
}
void pluss(ll p,ll l,ll r,ll v){
if(t[p].l>=l&&t[p].r<=r){
t[p].pt=(t[p].pt+v)%m;
t[p].v=(t[p].v+(t[p].r-t[p].l+1)*v)%m;
return;
}
lazy(p);
t[p].v=(t[p*2].v+t[p*2+1].v)%m;
ll mid=(t[p].l+t[p].r)/2;
if(l<=mid)pluss(p*2,l,r,v);
if(r>mid)pluss(p*2+1,l,r,v);
t[p].v=(t[p*2].v+t[p*2+1].v)%m;
}
void timer(ll p,ll l,ll r,ll v){
if(t[p].l>=l&&t[p].r<=r){
t[p].tt=(t[p].tt*v)%m;
t[p].v=(t[p].v*v)%m;
t[p].pt=(t[p].pt*v)%m;
return;
}
lazy(p);
t[p].v=(t[p*2].v+t[p*2+1].v)%m;
ll mid=(t[p].l+t[p].r)/2;
if(l<=mid)timer(p*2,l,r,v);
if(r>mid)timer(p*2+1,l,r,v);
t[p].v=(t[p*2].v+t[p*2+1].v)%m;
}
ll query(ll p,ll l,ll r){
if(t[p].l>=l&&t[p].r<=r)return t[p].v;
lazy(p);
ll ans=0,mid=(t[p].l+t[p].r)/2;
if(l<=mid)ans=(ans+query(p*2,l,r))%m;
if(r>mid)ans=(ans+query(p*2,l,r))%m;
return ans;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>q>>m;
for(int i=1;i<=n;i++)cin>>a[i];
est(1,1,n);
for(int i=1;i<=q;i++){
int op;cin>>op;
if(op==1){
ll x,y,k;
timer(1,x,y,k);
continue;
}
if(op==2){
ll x,y,k;
pluss(1,x,y,k);
continue;
}
if(op==3){
ll x,y;
cout<<query(1,x,y)<<"\n";
continue;
}
}
return 0;
}