csp前回来刷遍板子,
十几分钟写完了,认为自己很对
wa的不成样,都是在成百上千行处
求救同机房dalao无果
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
inline long long r_ll(){
long long f=1,x=0;int c;
do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9');
do{x=(x<<3)+(x<<1)+c-'0',c=getchar();}while(c>='0'&&c<='9');
return f*x;
}
int n,m;
long long a[100010];
long long mod;
struct SEG_TREE{
int l;
int r;
long long val;
long long pls;
long long mul;
}tr[400010];
inline void pud(int now){
if(tr[now].mul>1){
tr[now<<1].val*=tr[now].mul,tr[now<<1].val%=mod;
tr[now<<1].mul*=tr[now].mul,tr[now<<1].mul%=mod;
tr[now<<1].pls*=tr[now].mul,tr[now<<1].pls%=mod;
tr[now<<1|1].val*=tr[now].mul,tr[now<<1|1].val%=mod;
tr[now<<1|1].mul*=tr[now].mul,tr[now<<1|1].mul%=mod;
tr[now<<1|1].pls*=tr[now].mul,tr[now<<1|1].pls%=mod;
tr[now].mul=1;
}
if(tr[now].pls){
tr[now<<1].val+=(tr[now<<1].r-tr[now<<1].l+1)*tr[now].pls,tr[now<<1].val%=mod;
tr[now<<1].pls+=tr[now].pls,tr[now<<1].pls%=mod;
tr[now<<1|1].val+=(tr[now<<1|1].r-tr[now<<1|1].l+1)*tr[now].pls,tr[now<<1|1].val%=mod;
tr[now<<1|1].pls+=tr[now].pls,tr[now<<1|1].pls%=mod;
tr[now].pls=0;
}
return;
}
inline void upd(int now){
tr[now].val=(tr[now<<1].val+tr[now<<1|1].val)%mod;
return;
}
void build(int now,int l,int r){
tr[now].l=l,tr[now].r=r;
tr[now].mul=1;
tr[now].pls=0;
if(l==r){
tr[now].val=a[l];
return;
}
int mid=l+r>>1;
build(now<<1,l,mid);
build(now<<1|1,mid+1,r);
upd(now);
return;
}
void chg1(int now,int l,int r,long long k){//*
if(l<=tr[now].l&&tr[now].r<=r){
tr[now].val*=k,tr[now].val%=mod;
tr[now].mul*=k,tr[now].mul%=mod;
tr[now].pls*=k,tr[now].pls%=mod;
return;
}
int mid=tr[now].l+tr[now].r>>1;
pud(now);
if(l<=mid){
chg1(now<<1,l,r,k);
}
if(r>mid){
chg1(now<<1|1,l,r,k);
}
upd(now);
return;
}
void chg2(int now,int l,int r,long long k){//+
if(l<=tr[now].l&&tr[now].r<=r){
tr[now].val+=k*(tr[now].r-tr[now].l+1),tr[now].val%=mod;
tr[now].pls+=k,tr[now].pls%=mod;
return;
}
int mid=tr[now].l+tr[now].r>>1;
pud(now);
if(l<=mid){
chg2(now<<1,l,r,k);
}
if(r>mid){
chg2(now<<1|1,l,r,k);
}
upd(now);
return;
}
long long qry(int now,int l,int r){
if(l<=tr[now].l&&tr[now].r<=r){
return tr[now].val%mod;
}
pud(now);
int mid=tr[now].l+tr[now].r>>1;
return ((l<=mid?qry(now<<1,l,r):0)+(r>mid?qry(now<<1|1,l,r):0))%mod;
}
int main(){
n=r_ll(),m=r_ll(),mod=r_ll();
for(int i=1;i<=n;i++){
a[i]=r_ll();
}
build(1,1,n);
for(int i=1;i<=m;i++){
int opt=r_ll();
long long x,y,k;
if(opt==1){
x=r_ll(),y=r_ll(),k=r_ll();
chg1(1,x,y,k);
}else if(opt==2){
x=r_ll(),y=r_ll(),k=r_ll();
chg2(1,x,y,k);
}else{
x=r_ll(),y=r_ll();
printf("%lld\n",qry(1,x,y));
}
}
return 0;
}