0分求调,全WA
查看原帖
0分求调,全WA
713098
Koei楼主2025/8/5 11:36
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn(1e5+10);
ll n,q,mod;
ll a[maxn];
ll s[4*maxn];
ll mul[4*maxn],add[4*maxn];
inline void pushup(ll now){
	s[now]=(s[now*2]+s[now*2+1])%mod;
}
void build(ll now,ll l,ll r){
	if(l==r){
		s[now]=a[l];
		return;
	}
	ll mid((l+r)/2);
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
	pushup(now);
}
inline void pushdown(ll now,ll ln,ll rn){
	if(add[now]==0&&mul[now]==1){
		return;
	}
	s[now*2]=(s[now*2]*mul[now]+add[now]*ln)%mod;
	s[now*2+1]=(s[now*2+1]*mul[now]+add[now]*rn)%mod;
	add[now*2]=(add[now*2]*mul[now]+add[now])%mod;
	add[now*2+1]=(add[now*2+1]*mul[now]+add[now])%mod;
	add[now]=0;
	mul[now*2]=(mul[now*2]*mul[now])%mod;
	mul[now*2+1]=(mul[now*2+1]*mul[now])%mod;
	mul[now]=1;
}
void cf(ll L,ll R,ll k,ll now,ll l,ll r){
	if(L<=l&&r<=R){
		s[now]=(s[now]*k)%mod;
		s[now]%=mod;
		mul[now]*=k;
		return;
	}
	ll mid((l+r)/2);
	pushdown(now,mid-l+1,r-mid);
	if(L<=mid){
		cf(L,R,k,now*2,l,mid);
	}
	if(mid<R){
		cf(L,R,k,now*2+1,mid+1,r);
	}
	pushup(now);
}
void jf(ll L,ll R,ll k,ll now,ll l,ll r){
	if(L<=l&&r<=R){
		s[now]+=(k*(r-l+1))%mod;
		s[now]%=mod;
		add[now]+=k;
		return;
	}
	ll mid((l+r)/2);
	pushdown(now,mid-l+1,r-mid);
	if(L<=mid){
		jf(L,R,k,now*2,l,mid);
	}
	if(mid<R){
		jf(L,R,k,now*2+1,mid+1,r);
	}
	pushup(now);
}
ll qry(ll L,ll R,ll now,ll l,ll r){
	if(L<=l&&r<=R){
		return s[now];
	}
	ll mid((l+r)/2);
	pushdown(now,mid-l+1,r-mid);
	ll ans(0);
	if(L<=mid){
		ans+=qry(L,R,now*2,l,mid);
		ans%=mod;
	}
	if(mid<R){
		ans+=qry(L,R,now*2+1,mid+1,r);
		ans%=mod;
	}
	return ans;
}
int main(){
	cin>>n>>q>>mod;
	for(ll i(1);i<=4*n;i++){
		mul[i]=1;
	}
	for(ll i(1);i<=n;i++){
		cin>>a[i];
	}
	build(1,1,n);
	while(q--){
		ll o,x,y,k;
		cin>>o>>x>>y;
		if(o!=3){
			cin>>k;
		}
		if(o==1){
			cf(x,y,k,1,1,n);
		}else if(o==2){
			jf(x,y,k,1,1,n);
		}else{
			cout<<qry(x,y,1,1,n)%mod<<'\n';
		}
	}
	return 0;
}

附赠第一组数据:

in
8 10 571373
5929 7152 8443 6028 8580 5449 8473 4237 
2 4 8 4376
1 2 8 9637
2 2 6 7918
2 5 8 5681
3 2 8
1 1 5 6482
3 1 5
1 5 8 8701
2 5 8 7992
2 5 8 7806
out
478836
562114
2025/8/5 11:36
加载中...