- BC20260050's blog
1
- 2025-2-8 8:30:03 @
#include<bits/stdc++.h> using namespace std; #define int long long const int N=1e5+10; int n,m,a[N],val[N4]; void build(int l,int r,int num){ if(l==r){ val[num]=a[l]; return ; } int mid=l+((r-l)>>1); build(l,mid,num2); build(mid+1,r,num2+1); val[num]=val[num2+1]+val[num2]; } void qwq(int l,int r,int x,int y,int num){ if(l==r){ val[num]+=y; return ; } int mid=l+((r-l)>>1); if(x<=mid){ qwq(l,mid,x,y,num2); }else{ qwq(mid+1,r,x,y,num2+1); } val[num]=val[num2+1]+val[num2]; } int qvq(int l,int r,int x,int y,int num){ if(l>=x&&r<=y){ return val[num]; } int mid=l+((r-l)>>1),ans=0; if(x<=mid)ans+=qvq(l,mid,x,y,num2); if(mid<y)ans+=qvq(mid+1,r,x,y,num*2+1); return ans; } signed main(){ scanf("%lld %lld",&n,&m); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); for(int i=n;i>=1;i--){ a[i]-=a[i-1]; } build(1,n,1); for(int i=1;i<=m;i++){ int t,l,r,k,d; scanf("%lld %lld",&t,&x); if(t==1){ qwq(1,n,x,y,1); }else{ printf("%lld\n",qvq(1,n,x,y,1)); } } return 0; }