#define DeBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <sstream>
#include <map>
#include <bitset>
using namespace std ;
#define zero {0}
#define INF 2000000000
#define EPS 1e-6
typedef long long LL;
const double PI = acos(-1.0);
//#pragma comment(linker, "/STACK:102400000,102400000")
inline int sgn(double x)
{
return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);
}
#define MAX 50005
inline int lowbit(int x)
{
return (x & (-x));
}
int a[MAX], n;
void add(int index, int num)
{
while (index <= n)
{
a[index] += num;
index += lowbit(index);
}
}
int Sum(int x)
{
int sum = 0;
while (x > 0)
{
sum += a[x];
x -= lowbit(x);
}
return sum;
}
int cnt=1;
int main()
{
#ifdef DeBUGs
freopen("//home//amb//桌面//1.in", "r", stdin);
#endif
int T;
scanf("%d", &T);
while (T--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
printf("Case %d:\n", cnt++);
int it;
for(int i=1;i<=n;i++)
{
scanf("%d",&it);
add(i,it);
}
char s[10];
int a1,a2;
while(scanf("%s",s),s[0]!='E')
{
scanf("%d%d",&a1,&a2);
if(s[0]=='A')
add(a1,a2);
else if(s[0]=='S')
add(a1,-a2);
else
printf("%d\n", Sum(a2)-Sum(a1-1));
}
}
return 0;
}
hdu1166树状数组模板题
最新推荐文章于 2019-08-08 10:25:56 发布