RT
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,m;
ll Mod;
ll in[maxn];
inline ll read()
{
ll x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
{
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
struct node
{
int l,r;
int sum,mul_lazy,add_lazy;
}tree[maxn<<1];
inline ll ls(ll i){return i<<1;}
inline ll rs(ll i){return i<<1|1;}
inline void pushup(ll i){tree[i].sum=(tree[rs(i)].sum+tree[ls(i)].sum)%Mod;}
inline void pushdown(ll i)
{
ll a=tree[i].mul_lazy;ll b=tree[i].add_lazy;
tree[ls(i)].sum=(tree[ls(i)].sum*a+b*(tree[ls(i)].r-tree[ls(i)].l+1))%Mod;
tree[rs(i)].sum=(tree[ls(i)].sum*a+b*(tree[rs(i)].r-tree[rs(i)].l+1))%Mod;
tree[ls(i)].mul_lazy=(tree[ls(i)].mul_lazy*a)%Mod;
tree[rs(i)].mul_lazy=(tree[rs(i)].mul_lazy*a)%Mod;
tree[ls(i)].add_lazy=(tree[ls(i)].add_lazy*a+b)%Mod;
tree[rs(i)].add_lazy=(tree[rs(i)].add_lazy*a+b)%Mod;
tree[i].add_lazy=0;
tree[i].mul_lazy=1;
return;
}
inline void build(ll i,ll l,ll r)
{
tree[i].l=l;tree[i].r=r;tree[i].mul_lazy=1;
if(l==r){tree[i].sum=in[i]%Mod;return;}
ll mid=(l+r)>>1;
build(ls(i),l,mid);
build(rs(i),mid+1,r);
pushup(i);
}
inline void mul(ll i,ll l,ll r,ll k)
{
if(tree[i].l>r||tree[i].r<l)return ;
if(tree[i].l>=l&&tree[i].r<=r)
{
tree[i].sum=(tree[i].sum*k)%Mod;
tree[i].mul_lazy=(tree[i].mul_lazy*k)%Mod;
tree[i].add_lazy=(tree[i].add_lazy*k)%Mod;
}
pushdown(i);
if(tree[ls(i)].r>=l)mul(ls(i),l,r,k);
if(tree[rs(i)].l<=r)mul(rs(i),l,r,k);
pushup(i);
return;
}
inline void add(ll i,ll l,ll r,ll k)
{
if(tree[i].l>r||tree[i].r<l)return;
if(tree[i].l>=l&&tree[i].r<=r)
{
tree[i].sum+=(tree[i].r-tree[i].l+1)*k%Mod;
tree[i].add_lazy=(tree[i].add_lazy+k)%Mod;
}
pushdown(i);
if(tree[ls(i)].r>=l)add(ls(i),l,r,k);
if(tree[rs(i)].l<=r)add(rs(i),l,r,k);
pushup(i);
return;
}
inline ll search(ll i,ll l,ll r)
{
if(tree[i].l>r||tree[i].r<l)return 0;
if(tree[i].l>=l&&tree[i].r<=r)return tree[i].sum;
pushdown(i);
ll ans=0;
if(tree[ls(i)].r>=l)ans+=search(ls(i),l,r);
if(tree[rs(i)].l<=r)ans+=search(rs(i),l,r);
return ans%Mod;
}
int main()
{
scanf("%d %d %lld",&n,&m,&Mod);
for(register int i=1;i<=n;i++)
{
in[i]=read();
}
build(1,1,n);
for(register int i=1;i<=m;i++)
{
int cz;
cz=read();
if(cz==1)
{
ll l,r,k;
l=read();r=read();k=read();
mul(1,l,r,k);
}
else if(cz==2)
{
ll l,r,k;
l=read();r=read();k=read();
add(1,l,r,k);
}
else if(cz==3)
{
ll l,r;
l=read();r=read();
printf("%lld\n",search(1,l,r));
}
}
return 0;
}
线段树果然学不得qwq