【树状数组 单点修改,区间求值】hdu 1166 敌兵布阵
2017-08-15 10:20
429 查看
Link:http://acm.hdu.edu.cn/showproblem.php?pid=1166
#include <bits/stdc++.h> using namespace std; const int N = 5e4+5; char s[10]; int tree ,n; void add(int x,int num){ while(x<=n){ tree[x]+=num; x += x&(-x); } } int getpre(int x){ int ans = 0; while(x){ ans+=tree[x]; x -= x&(-x); } return ans; } int query(int x,int y){ return getpre(y)-getpre(x-1); } int main(){ int T,a; scanf("%d",&T); for(int cas=1; cas<=T; cas++){ memset(tree,0,sizeof(tree)); scanf("%d",&n); for(int i = 1; i <= n; i++) { scanf("%d",&a); add(i,a); } printf("Case %d:\n",cas); int x,y; while(~scanf("%s",s)){ if(strcmp(s,"End")==0) break; scanf("%d%d",&x,&y); if(strcmp(s,"Add")==0) add(x,y); else if(strcmp(s,"Sub")==0) add(x,-y); else printf("%d\n",query(x,y)); } } return 0; }
相关文章推荐
- HDU 1166 敌兵布阵(树状数组 or 线段树 单点修改 区间求和)
- HDU 1166 敌兵布阵 (树状数组--单点更新,区间求值)
- hdu 1166 敌兵布阵 树状数组求区间和和修改点的值
- 树状数组:HDU1166敌兵布阵 【单点更新,区间查询】
- Hdu 1166 敌兵布阵 树状数组 或 线段树 单点更新,区间求和
- HDU 1166 敌兵布阵(数状数组)第一种:每次修改的是一个点,所求的是关于某段区间
- HDU 1166 敌兵布阵 <线段树 单点修改 区间查询>
- 【算法系列学习】线段树vs树状数组 单点修改,区间查询 [kuangbin带你飞]专题七 线段树 A - 敌兵布阵
- hdu 1166 敌兵布阵 单点更新 树状数组 线段树 两种做法
- 【原创】【数据结构】一维树状数组的基本操作(单点修改,区间查询) (HDU1166 敌兵布阵)
- hdu1166敌兵布阵(线段树---单点更新,区间求值)
- 1166 敌兵布阵 树状数组单点修改
- HDU - 3584 Cube (三维树状数组 + 区间修改 + 单点求值)
- 敌兵布阵 HDU - 1166 (线段树单点修改区间求和模板)
- HDU - 1556 Color the ball (一维树状数组 + 区间修改 + 单点求值)
- HDU 1166 敌兵布阵(树状数组||线段树单点更新)
- 线段树系列-hdu-1166-敌兵布阵-单点修改区间求和
- HDU 1166 敌兵布阵 (我的树状数组加线段树点修改模板)
- hdu 1556 Color the ball 【树状数组:区间修改、单点求值】
- hdoj 1166 敌兵布阵 【单点更新+区间求和】 【线段树】 【树状数组】