題意:單點更新,區間查詢
樹狀數組裸題:
#include#include #include #include #include #include using namespace std; #define ll int #define N 200010 int tree[N], maxn; int lowbit(int x){return x&(-x);} int sum(int x){ int ans = 0; while(x>=1){ans+=tree[x]; x-=lowbit(x);} return ans; } void change(int x, int val){ while(x <= maxn) {tree[x] += val; x+=lowbit(x);} } char s[3]; ll num[N]; int main(){ ll n, u, v, Cas = 1; while(scanf("%d",&n),n){ memset(tree, 0, sizeof(tree));maxn = n; for(int i = 1; i <= n; i++){scanf("%d",&num[i]); change(i, num[i]);} if(Cas>1)puts(""); printf("Case %d:\n", Cas++); while(1){ scanf("%s",s); if(s[0]=='E')break; scanf("%d %d",&u,&v); if(s[0]=='S'){ change(u, -num[u]); change(u, v); num[u] = v; } else printf("%d\n", sum(v)-sum(u-1)); } } return 0; }