1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 5 #define ll long long 6 7 using namespace std; 8 9 ll c[100005]; 10 ll addv[320]; 11 ll sum[320]; 12 int n,m,g,p=1,ks=1; //g每块大小 p临时指针 ks块数 13 int f,x,y,pl,pr; //pl左指针 pr右指针 14 ll k,ans; 15 16 int main(){ 17 scanf("%d%d",&n,&m); 18 for(int i=1;i<=n;i++)scanf("%lld",&c[i]); 19 memset(addv,0,sizeof(addv)); 20 g=sqrt(n); 21 for(int i=1;i<=n;i++){ 22 if(p>g){ 23 p=1; 24 ks++; 25 } 26 sum[ks]+=c[i]; 27 p++; 28 } 29 for(int i=1;i<=m;i++){ 30 scanf("%d",&f); 31 if(f==1){ 32 scanf("%d%d%lld",&x,&y,&k); 33 if(x%g)pl=(x/g)+1;else pl=x/g; 34 if(y%g)pr=(y/g)+1;else pr=y/g; 35 if(x!=(pl-1)*g+1){ 36 while(x<=pl*g){ 37 c[x]+=k; 38 sum[pl]+=k; 39 x++; 40 } 41 pl++; 42 } 43 if(y!=pr*g){ 44 while(y>(pr-1)*g){ 45 c[y]+=k; 46 sum[pr]+=k; 47 y--; 48 } 49 pr--; 50 } 51 for(int j=pl;j<=pr;j++){ 52 addv[j]+=k; 53 sum[j]+=k*g; 54 } 55 } 56 else{ 57 scanf("%d%d",&x,&y); 58 if(x%g)pl=(x/g)+1;else pl=x/g; 59 if(y%g)pr=(y/g)+1;else pr=y/g; 60 ans=0; 61 if(x!=(pl-1)*g+1){ 62 while(x<=pl*g){ 63 ans+=c[x]+addv[pl]; 64 x++; 65 } 66 pl++; 67 } 68 if(y!=pr*g){ 69 while(y>(pr-1)*g){ 70 ans+=c[y]+addv[pr]; 71 y--; 72 } 73 pr--; 74 } 75 for(int j=pl;j<=pr;j++)ans+=sum[j]; 76 printf("%lld ",ans); 77 } 78 } 79 80 return 0; 81 }