题目
思路
这道题是树状数组区间修改的模板题
用差分数组解决就好了
代码
#include<iostream>
#include<cstdio>
using namespace std;
long long n,m,a[200010],b[200010],c[200010];
long long w,x,y,z;
void insert(long long x,long long y)
{
while(x<=n)
{
c[x]+=y;
x+=(x&-x);
}
}
long long query(long long x)
{
long long js=0;
while(x)
{
js+=c[x];
x-=(x&-x);
}
return js;
}
int main()
{
scanf("%lld%lld",&n,&m);
for(long long i=1; i<=n; i++)
scanf("%lld",&a[i]);
for(long long i=1; i<=n; i++)
{
b[i]=a[i]-a[i-1];
insert(i,b[i]);
}
while(m--)
{
scanf("%lld",&w);
if(w==1)
{
scanf("%lld%lld%lld",&x,&y,&z);
insert(x,z);
insert(y+1,-z);
}
else
{
scanf("%lld",&x);
printf("%lld\n",query(x));
}
}
return 0;
}