标签:cpp pre namespace lan while bsp space scanf 模板
#include<bits/stdc++.h> using namespace std; const int N=5e5+10; int a[N]; int c[N<<2]; int n,m; int lowbit(int x){ return x&-x; } void updata(int x,int k){ while(x<=n){ c[x]+=k; x+=lowbit(x); } } int getsum(int x){ int ans=0; while(x){ ans+=c[x]; x-=lowbit(x); } return ans; } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); updata(i,a[i]-a[i-1]); } for(int i=1;i<=m;i++){ int go; scanf("%d",&go); if(go==1){ int x,y,k; scanf("%d%d%d",&x,&y,&k); updata(x,k); updata(y+1,-k); } if(go==2){ int x; scanf("%d",&x); printf("%d\n",getsum(x)); } } return 0; }
标签:cpp pre namespace lan while bsp space scanf 模板
原文地址:https://www.cnblogs.com/LightyaChoo/p/13204740.html