1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include<bits/stdc++.h> #define maxn 100010 #define LL long long #define left l,mid,k<<1 #define right mid+1,r,k<<1|1 #define lef k<<1 #define rig k<<1|1 using namespace std; int n,m,p,s,x,y; long long sum[maxn*4],kk,lazy_ad[maxn*4],lazy_mu[maxn*4]; inline int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1; ch=getchar();} while(ch<='9'&&ch>='0') s=s*10+ch-'0',ch=getchar(); return s*w; } inline void build(int l,int r,int k) { lazy_mu[k]=1; if(l==r) sum[k]=read(); else { int mid=(l+r)>>1; build(left); build(right); sum[k]=(sum[lef]+sum[rig])%p; } return ; } inline void push(int l,int r,int k,LL a,LL b) { lazy_ad[k]=(lazy_ad[k]*b+a)%p; lazy_mu[k]=(lazy_mu[k]*b)%p; sum[k]=(sum[k]*b+(r-l+1)*a)%p; } inline void down(int l,int r,int k) { int mid=(l+r)>>1; push(left,lazy_ad[k],lazy_mu[k]); push(right,lazy_ad[k],lazy_mu[k]); lazy_ad[k]=0; lazy_mu[k]=1; return ; } inline void midefy(int l,int r,int k,LL a,LL b) { if(x<=l&&r<=y) push(l,r,k,a,b); else { if(lazy_ad[k]!=0||lazy_mu[k]!=1) down(l,r,k); int mid=(l+r)>>1; if(x<=mid) midefy(left,a,b); if(y>mid) midefy(right,a,b); sum[k]=(sum[lef]+sum[rig])%p; } return ; } inline LL ask(int l,int r,int k) { if(x<=l&&r<=y) return sum[k]; if(lazy_ad[k]!=0||lazy_mu[k]!=1) down(l,r,k); int mid=(l+r)>>1; LL ans=0; if(x<=mid) ans=(ans+ask(left))%p; if(y>mid) ans=(ans+ask(right))%p; return ans; } int main() { n=read(); m=read(); p=read(); build(1,n,1); while(m--) { s=read();x=read(); y=read(); if(s==1) { kk=read(); midefy(1,n,1,0,kk); } else if(s==2) { kk=read(); midefy(1,n,1,kk,1); } else printf("%lld\n",ask(1,n,1)); } return 0; }
|