#include<bits/stdc++.h>usingnamespacestd;#define int long longconstexprintsi=2e5+10;intn,m,t;inta[si],add[si],belong[si];intL[si],R[si],sum[si];inlinevoidchange(intl,intr,intv){intp=belong[l],q=belong[r];if(p==q){for(registerinti=l;i<=r;++i){a[i]+=v;}sum[p]+=v*(r-l+1);}else{for(registerinti=l;i<=R[p];++i){a[i]+=v;}sum[p]+=v*(R[p]-l+1);for(registerinti=L[q];i<=r;++i){a[i]+=v;}sum[q]+=v*(r-L[q]+1);for(registerinti=p+1;i<=q-1;++i){add[i]+=v;}}}inlineintquery(intl,intr){intp=belong[l],q=belong[r];intres=0;if(p==q){for(registerinti=l;i<=r;++i){res+=a[i];}res+=add[p]*(r-l+1);}else{for(registerinti=l;i<=R[p];++i){res+=a[i];}res+=add[p]*(R[p]-l+1);for(registerinti=L[q];i<=r;++i){res+=a[i];}res+=add[q]*(r-L[q]+1);for(registerinti=p+1;i<=q-1;++i){res+=sum[i],res+=add[i]*(R[i]-L[i]+1);}}returnres;}signedmain(){scanf("%lld%lld",&n,&m),t=sqrt(n*1.0);for(registerinti=1;i<=n;++i){scanf("%lld",&a[i]);}for(registerinti=1;i<=t;++i){L[i]=(i-1)*sqrt(n*1.0)+1,R[i]=i*sqrt(n*1.0);}if(R[t]<n)++t,L[t]=R[t-1]+1,R[t]=n;for(registerinti=1;i<=t;++i){for(registerintj=L[i];j<=R[i];++j){sum[i]+=a[j],belong[j]=i;}}while(m--){intop,l,r;scanf("%lld%lld%lld",&op,&l,&r);if(op==1){intk;scanf("%lld",&k);change(l,r,k);}elseprintf("%lld\n",query(l,r));}return0;}
#include<bits/stdc++.h>usingnamespacestd;#define int long longconstexprintsi=2e5+10;intn,m,t;inta[si],add[si],belong[si];intL[si],R[si],sum[si];inlinevoidchange(intl,intr,intv){intp=belong[l],q=belong[r];if(p==q){for(registerinti=l;i<=r;++i){a[i]+=v;}sum[p]+=v*(r-l+1);}else{for(registerinti=l;i<=R[p];++i){a[i]+=v;}sum[p]+=v*(R[p]-l+1);for(registerinti=L[q];i<=r;++i){a[i]+=v;}sum[q]+=v*(r-L[q]+1);for(registerinti=p+1;i<=q-1;++i){add[i]+=v;}}}inlineintquery(intl,intr,intmod){intp=belong[l],q=belong[r];intres=0;if(p==q){for(registerinti=l;i<=r;++i){res=(res+a[i])%mod;}res=(res+add[p]*(r-l+1))%mod;}else{for(registerinti=l;i<=R[p];++i){res=(res+a[i])%mod;}res=(res+add[p]*(R[p]-l+1))%mod;for(registerinti=L[q];i<=r;++i){res=(res+a[i])%mod;}res=(res+add[q]*(r-L[q]+1))%mod;for(registerinti=p+1;i<=q-1;++i){res=(res+sum[i])%mod,res=(res+add[i]*(R[i]-L[i]+1))%mod;}}returnres%mod;}signedmain(){scanf("%lld",&n),t=sqrt(n);for(registerinti=1;i<=n;++i){scanf("%lld",&a[i]);}for(registerinti=1;i<=t;++i){L[i]=(i-1)*sqrt(n)+1,R[i]=i*sqrt(n);}if(R[t]<n)++t,L[t]=R[t-1]+1,R[t]=n;for(registerinti=1;i<=t;++i){for(registerintj=L[i];j<=R[i];++j){sum[i]+=a[j],belong[j]=i;}}for(registerinti=1;i<=n;++i){intop,l,r,c;scanf("%lld%lld%lld%lld",&op,&l,&r,&c);if(op==0)change(l,r,c);elseprintf("%lld\n",query(l,r,c+1));}return0;}
#include<bits/stdc++.h>usingnamespacestd;constexprintsi=5e4+10;intn,t;inta[si],add[si],belong[si];intL[si],R[si],sum[si],maxv[si];inlinevoidchange(intl,intr){intp=belong[l],q=belong[r];if(p==q){if(maxv[p]==0||maxv[p]==1)return;for(registerinti=l;i<=r;++i){intrmp=a[i];a[i]=sqrt(a[i]),sum[p]-=(rmp-a[i]);}intmx=0;for(registerinti=L[p];i<=R[p];++i){mx=max(mx,a[i]);}maxv[p]=mx;}else{if(maxv[p]!=0&&maxv[p]!=1){for(registerinti=l;i<=R[p];++i){intrmp=a[i];a[i]=sqrt(a[i]),sum[p]-=(rmp-a[i]);}intmx=0;for(registerinti=L[p];i<=R[p];++i){mx=max(mx,a[i]);}maxv[p]=mx;}if(maxv[q]!=0&&maxv[q]!=1){for(registerinti=L[q];i<=r;++i){intrmp=a[i];a[i]=sqrt(a[i]),sum[q]-=(rmp-a[i]);}intmx=0;for(registerinti=L[q];i<=R[q];++i){mx=max(mx,a[i]);}maxv[q]=mx;}for(registerinti=p+1;i<=q-1;++i){if(maxv[i]==0||maxv[i]==1)continue;intmx=0;for(registerintj=L[i];j<=R[i];++j){intrmp=a[j];a[j]=sqrt(a[j]),sum[i]-=(rmp-a[j]);mx=max(mx,a[j]);}maxv[i]=mx;}}}inlineintquery(intl,intr){intp=belong[l],q=belong[r];intres=0;if(p==q){for(registerinti=l;i<=r;++i){res+=a[i];}}else{for(registerinti=l;i<=R[p];++i){res+=a[i];}for(registerinti=L[q];i<=r;++i){res+=a[i];}for(registerinti=p+1;i<=q-1;++i){res+=sum[i];}}returnres;}intmain(){scanf("%d",&n),t=sqrt(n);for(registerinti=1;i<=n;++i){scanf("%d",&a[i]);}for(registerinti=1;i<=t;++i){L[i]=(i-1)*sqrt(n)+1,R[i]=i*sqrt(n);}if(R[t]<n)++t,L[t]=R[t-1]+1,R[t]=n;for(registerinti=1;i<=t;++i){for(registerintj=L[i];j<=R[i];++j){belong[j]=i,sum[i]+=a[j],maxv[i]=max(maxv[i],a[j]);}}for(registerinti=1;i<=n;++i){intop,l,r,c;scanf("%d%d%d%d",&op,&l,&r,&c);if(op==0)change(l,r);elseprintf("%d\n",query(l,r));}return0;}// it is better to use tag & rem the time of sqrt.