#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long c[ N ];
long long d[ N ];
void addc( int i , long long x ){
while( i <= N ){
c[ i ] += x;
i += ( i & ( -i ) );
}
}
long long sumc(int i){
long long tot = 0;
while( i > 0 ){
tot += c[ i ];
i -= ( i & ( - i ) );
}
return tot;
}
void addd( int i , long long x ){
while( i <= N ){
d[ i ] += x;
i += ( i & ( -i ) );
}
}
long long sumd(int i){
long long tot = 0;
while( i > 0 ){
tot += d[ i ];
i -= ( i & ( - i ) );
}
return tot;
}
int main(){
int n , m;
cin >> n >> m;
int t = 0;
for( int i = 1 ; i <= n ; i ++ ){
int x;
cin >> x;
addc( i , x - t );
addd( i , ( i - 1 )*( x - t ) );
t = x;
}
for(int i = 1 ; i <= m ; i ++ ){
long long p;
cin >> p;
if( p == 1 ){
long long x,y,z;
cin >> x >> y >> z ;
addc( x , z );
addc( y + 1 , - z );
addd( x , ( x - 1 ) * z );
addd( y + 1 , y * - z );
}else{
long long x , y;
cin >> x >> y ;
cout << ( ( y ) * sumc( y ) - sumd( y ) ) - ( ( x - 1 ) * sumc( x - 1 ) - sumd( x - 1 )) << '\n';
}
}
return 0;
}