题解:
树状数组模板提
代码:
#include<bits/stdc++.h> using namespace std; const int N=50005; 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=0; for (;x;x-=x&-x)ans+=num[x]; return ans; } int main() { scanf("%d",&n); for (int i=1;i<=n;i++)scanf("%d",&a[i]),insert(i,a[i]-a[i-1]); for (int i=1;i<=n;i++) { scanf("%d%d%d%d",&opt,&l,&r,&c); if (opt==1)printf("%d ",find(r)); else insert(l,c),insert(r+1,-c); } }