HDU 1166 敌兵布阵
2013-10-22 10:32
260 查看
转载请注明出处:忆梦http://blog.csdn.net/yimeng2013/article/details/12942309
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166树状数组模板题
注意:输入输出比较多,用cin和cout会超时
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 50000+10 int c , a ; int n; int lowbit(int x) { return x & -x; } int sum(int x) { int ret = 0; while(x > 0) { ret += c[x]; x -= lowbit(x); } return ret; } void add(int x, int d) { while(x <= n) { c[x] += d; x += lowbit(x); } } int main () { int T; cin >> T; for(int t = 1; t <= T; t++) { printf("Case %d:\n", t); memset(c, 0, sizeof(c)); scanf("%d",&n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); add(i, a[i]); } char op[10]; int aa, bb; while(scanf("%s", op) != EOF) { if(op[0]=='E') break; scanf("%d %d", &aa, &bb); if(op[0] == 'Q') { printf("%d\n",sum(bb) - sum(aa-1) ); } else if(op[0] == 'A') { add(aa,bb); } else if(op[0] == 'S') { add(aa,-bb); } } } return 0; }
相关文章推荐
- HDU_1166_敌兵布阵
- HDU 1166 敌兵布阵(第一个树状数组)
- Hdu 1166 敌兵布阵 (树状数组版)
- HDU 1166 敌兵布阵
- hdu 1166 敌兵布阵 线段树 点更新
- HDU 1166 敌兵布阵 (线段树加法)
- hdu 1166 敌兵布阵
- HDU 1166 敌兵布阵 //线段树单点更新
- HDU-1166-线段树-敌兵布阵
- hdu 1166 敌兵布阵(cdq分治)
- HDU 1166敌兵布阵
- HDU 1166.敌兵布阵【线段树】【树状数组】【4月27】
- HDU-1166-敌兵布阵 (线段树)
- 【HDU 1166】敌兵布阵(树状数组)
- HDU_1166 敌兵布阵(线段树)
- HDU 1166 敌兵布阵 我的第一棵树,线段树,树状数组。
- hdu 1166 敌兵布阵
- HDU-1166 敌兵布阵 简单树状数组
- HDU 1166:敌兵布阵(线段树入门)
- HDU-1166- 敌兵布阵(树状数组 插点问线)