HDU 1166 敌兵布阵(树状数组)
来源:互联网 发布:手机版特效软件 编辑:程序博客网 时间:2024/04/30 06:37
单点修改,区间求和,可以用线段树, 也可以用树状数组。这里用树状数组写一波。
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int c[55555],n,T;int lowbit(int x){ return x&-x;}void add(int x,int y){ while(x <= n) { c[x] += y; x += lowbit(x); }}int getsum(int x){ int ans = 0; while(x) { ans += c[x]; x -= lowbit(x); } return ans;}int main(){ scanf("%d",&T); for(int cas = 1 ; cas <= T ; cas++) { //printf("%d\n",T); memset(c,0,sizeof(c)); scanf("%d",&n); for(int i = 1 ;i <= n ; i++) { int x; scanf("%d",&x); add(i,x); } char op[10]; int a,b; printf("Case %d:\n",cas); while(~scanf("%s",op)) { //printf("%s\n",op); if(op[0]=='E') break; scanf("%d%d",&a,&b); if(op[0]=='Q') printf("%d\n",getsum(b) - getsum(a-1)); else if(op[0]=='A') add(a,b); else if(op[0]=='S') add(a,-b); } } return 0;}
0 0
- hdu - 1166 - 敌兵布阵(树状数组)
- hdu 1166 敌兵布阵 (树状数组)
- HDU 1166 - 敌兵布阵(树状数组)
- hdu 1166 敌兵布阵 ( 树状数组 )
- HDU 1166 敌兵布阵(树状数组)
- hdu-1166敌兵布阵(树状数组)
- HDU 1166 敌兵布阵 (树状数组)
- hdu-1166 敌兵布阵(树状数组)
- hdu 1166 敌兵布阵(树状数组)
- hdu 1166 敌兵布阵(树状数组)
- HDU 1166 敌兵布阵(树状数组)
- HDU 1166 敌兵布阵(树状数组)
- HDU 1166 敌兵布阵 (树状数组)
- HDU 1166 敌兵布阵(树状数组)
- hdu 1166 敌兵布阵(树状数组)
- HDU 1166 敌兵布阵(树状数组)
- HDU 1166 敌兵布阵(树状数组)
- 树状数组 hdu 1166(敌兵布阵)
- HDU5171 GTY's birthday gift(矩阵快速幂)
- 2015年移动互联网十大趋势
- HDU 3887 Counting Offspring
- Linux多线程实践(3) --线程属性
- Java基础——再谈面向对象
- HDU 1166 敌兵布阵(树状数组)
- zend studio 10破解/汉化
- HDU 3001 Travelling
- Zipper(dfs)
- POJ 1195 Mobile phones
- HDU 1010 Tempter of the Bone
- MVC框架设计思想与设计理念
- 【转】在TCL中安装非市场应用
- Mac下使用SAE的问题们