就是区间修改单点查询。
题目分析用差分思想,用树状数组维护
C o d e Code Code#include#include #define lb(x) (x&-x) #define ll long long #define sco 1000010 using namespace std; ll n,m,c[sco]; inline void xg(ll x,ll y){for(;x<=n;x+=lb(x))c[x]+=y;} inline void add(ll l,ll r,ll x){xg(l,x);xg(r+1,-x);} inline ll sch(ll x){ ll ans=0;for(;x;x-=lb(x))ans+=c[x]; return ans; } int main(){ scanf("%lld%lld",&n,&m); for(ll i=1,x=0,y=0;i<=n;++i){ scanf("%lld",&x); xg(i,x-y); y=x; } for(ll i=1,opt,l,r,x;i<=m;++i){ scanf("%lld",&opt); if(opt==1){ scanf("%lld%lld%lld",&l,&r,&x); add(l,r,x); } else{ scanf("%lld",&x); printf("%lldn",sch(x)); } } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)