# BZOJ_1798_[AHOI2009]维护序列_线段树

BZOJ_1798_[AHOI2009]维护序列_线段树

mul[lson]=(mul[lson]*mul[pos])%p;

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define ls p<<1
#define rs p<<1|1
#define LL long long
#define N 100050
int a[N],n,m;
void bt(int l,int r,int p){
mul[p]=1;
if(l==r){
scanf("%lld",&t[p]);return ;
}
int mid=l+r>>1;
bt(l,mid,ls);bt(mid+1,r,rs);
t[p]=(t[ls]+t[rs])%mod;
}
void pud(int l,int r,int p){
int mid=l+r>>1;
mul[ls]=mul[ls]*mul[p]%mod;
mul[rs]=mul[rs]*mul[p]%mod;
}
void upad(int l,int r,int x,int y,int c,int p){
if(x<=l&&y>=r){
t[p]+=1ll*(r-l+1)*c;t[p]%=mod;
return ;
}
int mid=l+r>>1;
pud(l,r,p);
t[p]=(t[ls]+t[rs])%mod;
}
void upmu(int l,int r,int x,int y,int c,int p){
if(x<=l&&y>=r){
mul[p]=mul[p]*c%mod;
t[p]=t[p]*c%mod;
return ;
}
pud(l,r,p);
int mid=l+r>>1;
if(x<=mid)upmu(l,mid,x,y,c,ls);
if(y>mid)upmu(mid+1,r,x,y,c,rs);
t[p]=(t[ls]+t[rs])%mod;
}
LL query(int l,int r,int x,int y,int p){
if(x<=l&&y>=r)return t[p];
int mid=l+r>>1;
LL re=0;
pud(l,r,p);
if(x<=mid)re=(re+query(l,mid,x,y,ls))%mod;
if(y>mid)re=(re+query(mid+1,r,x,y,rs))%mod;
return re;
}
int main(){
scanf("%d%lld",&n,&mod);
bt(1,n,1);
scanf("%d",&m);
int op,x,y,z;
for(int i=1;i<=m;i++){
scanf("%d",&op);
if(op==1){
scanf("%d%d%d",&x,&y,&z);
upmu(1,n,x,y,z,1);
}else if(op==2){
scanf("%d%d%d",&x,&y,&z);