敌兵布阵(hdu1166)
水题
单点向上修改,区间向下查询
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define maxn 50010 using namespace std; int a[maxn],c[maxn],t,n; char s[10]; int lowbit(int x) { return x&(-x); } void add(int x,int d) { for(x;x<=n;x=x+lowbit(x)) c[x]=c[x]+d; } int sum(int x) { int s=0; for(x;x>0;x=x-lowbit(x)) s=s+c[x]; return s; } int main() { scanf("%d",&t); int ans=0,m=0,b=0,k=1; while(k<=t) { printf("Case %d:\n",k); memset(a,0,sizeof(a)); memset(c,0,sizeof(c)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); add(i,a[i]); } while(scanf("%s",s)&&s[0]!='E') { if(s[0]=='Q') { scanf("%d%d",&m,&b); ans=sum(b)-sum(m-1); printf("%d\n",ans); } if(s[0]=='A') { scanf("%d%d",&m,&b); add(m,b); } if(s[0]=='S') { scanf("%d%d",&m,&b); add(m,-b); } } k++; } }