1166 敌兵布阵

来源:互联网 发布:淘宝客服英文怎么说 编辑:程序博客网 时间:2024/06/11 04:46

题目:点击打开链接

#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int MAXN = 50010;int C[MAXN];int LowBit(int x){    return x & (-x);}void UFSet(int pos, int num, int n){    while(pos <= n)    {        C[pos] += num;        pos += LowBit( pos );    }}int Query(int pos, int sum){    while(pos > 0)    {        sum += C[pos];        pos -= LowBit( pos );    }    return sum;}int main(){    int T, n, i, pos, num;    int kcase = 1;    char str[6];    scanf("%d", &T);    while(T--)    {        printf("Case %d:\n",kcase++);        scanf("%d", &n);        memset(C, 0, sizeof(C));        for(i = 1; i <= n; ++i)        {            scanf("%d", &num);            UFSet(i, num, n);        }        while(scanf("%s", str))        {            if(str[0] == 'E')                break;            scanf("%d %d", &pos, &num);            if(str[0] == 'A')                UFSet(pos, num, n);            else if(str[0] == 'S')                UFSet(pos, -num, n);            else if(str[0] == 'Q')                printf("%d\n", Query(num, 0) - Query(pos-1, 0));        }    }    return 0;}


原创粉丝点击