分析:
区间修改单点查询 可用树状数组差分实现
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#define reg register
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,Q;
ll las,x,c[N];
ll lowbit(ll x){return x&(-x);}
void add(ll x,ll k)
{
for(;x<=n;x+=lowbit(x))
c[x]+=k;
}
ll query(ll x)
{
ll res=0;
for(;x;x-=lowbit(x))
res+=c[x];
return res;
}
int main()
{
scanf("%d%d%lld",&n,&Q,&las);
add(1,las);
for(int i=2;i<=n;i++)
{
scanf("%lld",&x);
add(i,x-las);
las=x;
}
while(Q--)
{
ll op,x,y,k;
scanf("%lld%lld",&op,&x);
if(op==1)
{
scanf("%lld%lld",&y,&k);
add(x,k);
add(y+1,-k);
}
if(op==2) printf("%lld\n",query(x));
}
return 0;
}