hdu1166之树状数组入门
来源:互联网 发布:淮北网络推广培训学校 编辑:程序博客网 时间:2024/06/06 08:35
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <queue>#include <algorithm>#include <map>#include <cmath>#include <iomanip>#define INF 99999999typedef long long LL;using namespace std;const int MAX=50000+10;int n;int sum[MAX],c[MAX];int lowbit(int x){//计算2^k return x&(-x);}void Update(int x,int y){while(x<=n){c[x]+=y;x=x+lowbit(x);}}int Query(int x){int sum=0;while(x>0){sum+=c[x];x=x-lowbit(x);}return sum;}int main(){int t,x,y,k,num=0;char a[10];scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",sum+i),sum[i]+=sum[i-1];for(int i=1;i<=n;++i){k=lowbit(i);c[i]=sum[i]-sum[i-k];}printf("Case %d:\n",++num);while(scanf("%s",a),a[0] != 'E'){cin>>x>>y;if(a[0] == 'A')Update(x,y);else if(a[0] == 'S')Update(x,-y);else printf("%d\n",Query(y)-Query(x-1));//cout<<Query(y)-Query(x-1)<<endl; }}return 0;}
0 0
- hdu1166之树状数组入门
- hdu1166(树状数组入门)
- hdu1166树状数组
- HDU1166树状数组
- hdu1166 树状数组
- hdu1166树状数组
- 树状数组 HDU1166
- hdu1166(树状数组)
- 树状数组-HDU1166
- Hdu1166 树状数组
- hdu1166 树状数组
- HDU1166(树状数组)
- 树状数组模板 HDU1166
- hdu1166(树状数组)
- HDU1166树状数组
- HDU1166 敌兵布阵 线段树||树状数组 入门题复习
- ACM-树状数组之敌兵布阵——hdu1166
- 树状数组专题(五)hdu1166
- 通过httpClient4读取页面内容
- 软件工程学习笔记(一)
- 类的内联函数
- myeclipse-pro-2014-GA-offline-installer-windows. MyEclipse2014GA激活工具
- httpclient4 取得cookie信息并保存
- hdu1166之树状数组入门
- MySQL的information_schema的介绍
- 图像处理职位面试题汇总(4)
- 容器vector
- rtlinitializeexceptionchain
- Android中ExpandableListView控件基本使用
- 关于commons-fileupload与struts2过滤器冲突的解决方法
- 【蓝桥杯】危险系数
- 大话设计模式-工厂方法模式(学习笔记)