【模板】4 树状数组2(区间修改单点求值)
#include<iostream>
#include<cstdio>
using namespace std;
int pd,c[500001],a[500001],x,y,k,n,m;
int lowbit(int xx)
{
return xx&-xx;
}
void update(int xx,int yy)
{
while(xx<=n)
{
c[xx]+=yy;
xx+=lowbit(xx);
}
}
int getsum(int xx)
{
int sum=0;
while(xx>0)
{
sum+=c[xx];
xx-=lowbit(xx);
}
return sum;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
update(i,a[i]-a[i-1]);
}
for(int i=1;i<=m;i++)
{
cin>>pd;
if(pd==1)
{
cin>>x>>y>>k;
update(x,k);
update(y+1,-k);
}
if(pd==2)
{
cin>>x;
cout<<getsum(x)<<endl;
}
}
return 0;
}
2019-09-09 By十四日的夏