#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cctype>
#include <queue>
#include <deque>
#include <ctime>
#include <cstring>
#include <string>
#define _e putchar (' ')
#define _v putchar ('\n')
#define ll long long
#define INF 999999999999999999ll
#define INE -999999999999999999ll
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;
inline int lowbit (int x) {
return x&(-x);
}
inline int mx(int x,int y) {
return x>y?x:y;
}
inline int mn(int x,int y) {
return x<y?x:y;
}
inline void r(ll &x) {
ll s=0,w=1;
char ch=getchar ();
while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar ();}
while(ch>='0'&&ch<='9') {s=(s<<1)+(s<<3)+(ch^48); ch=getchar ();}
x=s*w;
}
inline void wr(ll x) {
if(x<0) x=-x,putchar (45);
if(x<10) {
putchar (x+48);
return ;
}
wr(x/10);
putchar (x%10+48);
}
inline int ab (int x) {
if(x<0) return -x;
return x;
}
inline void swap (int &x,int &y) {
x^=y^=x^=y;
}
const int N=100005;
ll n,m,now,g,x,y,k,ans,a[N],w[N],sum[N],lt,rt,ex[N];
int main () {
r(n),r(m);
for(int i=1;i<=n;i++)
r(a[i]),sum[i]=sum[i-1]+a[i];
now=sqrt(n);
for(int i=1;i<=m;i++) {
r(g);
if(g==1) {
r(x),r(y),r(k);
if(x%now==1) lt=(x-1)/now+1;
else lt=(x-1)/now+2;
rt=y/now;
for(int j=lt;j<=rt;j++)
w[j]+=k;
for(int j=x;j<=(lt-1)*now;j++)
a[j]+=k,ex[lt-1]+=k;//ex为散块加,w为整块加
for(int j=rt*now+1;j<=y;j++)
a[j]+=k,ex[rt+1]+=k;
}
else {
r(x),r(y);
if(x%now==1) lt=(x-1)/now+1;
else lt=(x-1)/now+2;
rt=y/now;
ans=0;
for(int j=lt;j<=rt;j++)
ans+=w[j]*now+ex[j]+sum[j*now]-sum[(j-1)*now];
for(int j=x;j<=(lt-1)*now;j++)
ans+=a[j]+w[lt-1];
for(int j=rt*now+1;j<=y;j++)
ans+=a[j]+w[rt+1];
wr(ans),_v;
}
}
return 0;
}
我就是感觉很奇怪。。。是因为那些大佬的分块和我的写法不一样还是什么?