loj6277

时间:2024-01-14 15:50:56

题解:

树状数组模板提

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=;
int num[N],n,a[N],l,r,c,opt;
void insert(int x,int y)
{
for (;x<=n;x+=x&-x)num[x]+=y;
}
int find(int x)
{
int ans=;
for (;x;x-=x&-x)ans+=num[x];
return ans;
}
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)scanf("%d",&a[i]),insert(i,a[i]-a[i-]);
for (int i=;i<=n;i++)
{
scanf("%d%d%d%d",&opt,&l,&r,&c);
if (opt==)printf("%d\n",find(r));
else insert(l,c),insert(r+,-c);
}
}