HDU 1166(敌兵布阵)(树状数组 单点更新区间求和)
#include#include #include using namespace std;#define lowbit(x) x & (-x)//lowbit函数#define LL long long LL a[100005],n;void updata(LL x,LL v) { //更新函数 while(x<=n) { a[x]+=v; x+=lowbit(x); }}LL query(LL x) { //查询函数 LL sum=0; while(x) { sum+=a[x]; x-=lowbit(x); } return sum;}int main() { LL t; cin>>t; LL d=1; while(t--) { cout<<"Case "< <<":"< >n; LL s; memset(a,0,sizeof(a)); for(LL i=1; i<=n; i++) { cin>>s; updata(i,s); } string ss; int l,r; while(cin>>ss) { if(ss=="End"){ break; } cin>>l>>r; if(ss[0]=='A') { updata(l,r); } else if(ss[0]=='S') { updata(l,-r); } else { cout< <