#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 rd(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;
struct node {
ll s,lazy;
}tree[N*4];
ll n,m;
inline void pushup (ll u) {
tree[u].s=tree[u<<1].s+tree[u<<1|1].s;
}
inline void build (ll lt,ll rt,ll u) {
if(lt==rt) {
rd(tree[u].s);
return ;
}
ll mid=(lt+rt)>>1;
build (lt,mid,u<<1);
build (mid+1,rt,u<<1|1);
pushup (u);
}
inline void pushdown (ll lt,ll rt,ll u) {
if(lt==rt||!tree[u].lazy) return ;
tree[u<<1].lazy+=tree[u].lazy;
tree[u<<1|1].lazy+=tree[u].lazy;
ll mid=(lt+rt)>>1;
tree[u<<1].s+=tree[u].lazy*(mid-lt+1);
tree[u<<1|1].s+=tree[u].lazy*(rt-mid);
tree[u].lazy=0;
}
inline void update (ll lt,ll rt,ll delta,ll Lt,ll Rt,ll u) {
if(Lt<=lt&&rt<=Rt) {
tree[u].s+=(rt-lt+1)*delta;
tree[u].lazy+=delta;
return ;
}
pushdown (lt,rt,u);
ll mid=(lt+rt)>>1;
if(lt<=mid) update (lt,mid,delta,Lt,Rt,u<<1);
if(rt>mid) update (mid+1,rt,delta,Lt,Rt,u<<1|1);
pushup (u);
}
inline ll search_divide (ll lt,ll rt,ll Lt,ll Rt,ll u) {
if(Lt<=lt&&rt<=Rt) return tree[u].s;
pushdown (lt,rt,u);
ll mid=(lt+rt)>>1;
ll ans=0;
if(lt<=mid) ans+=search_divide(lt,mid,Lt,Rt,u<<1);
if(rt>mid) ans+=search_divide(mid+1,rt,Lt,Rt,u<<1|1);
return ans;
}
ll g,x,y,k;
int main () {
rd(n),rd(m);
build (1,n,1);
for(int i=1;i<=m;i++) {
rd(g);
if(g==2) {
rd(x),rd(y);
wr(search_divide(1,n,x,y,1)),_v;
}
else {
rd(x),rd(y),rd(k);
update (1,n,k,x,y,1);
}
}
return 0;
}
读入就炸了,求助