文件详细信息

下载本文件

本文件的大小为 724 字节。

#include<cstdio>
#define lowbit(x) (x&-x)
inline int read(){
	bool flag=true;
	int ch=getchar(),num=0;
	while(ch<48||ch>57){
		if(ch=='-')flag=false;
		ch=getchar();
	}
	while(ch>=48&&ch<=57)num=(num<<3)+(num<<1)+(ch^48),ch=getchar();
	return flag?num:-num;
}
const int maxn=1000005;
int n,q,op,l,r,x,last,now;
long long a[maxn];
void update(int u,int x){
	while(u<=n)a[u]+=x,u+=lowbit(u);
}
long long sum(int u){
	long long ans=0;
	while(u)ans+=a[u],u-=lowbit(u);
	return ans;
}
int main(){
	n=read(),q=read();
	for(int i=1;i<=n;i++)last=now,now=read(),update(i,now-last);
	while(q--){
		op=read(),l=read();
		if(op==1){
			r=read(),x=read();
			update(l,x),update(r+1,-x);
		}else printf("%lld\n",sum(l));
	}
	return 0; 
}