HDU 1166 树状数组 基础题
来源:互联网 发布:java多线程解压zip文件 编辑:程序博客网 时间:2024/06/05 12:04
/*中文题,很好理解。http://acm.hdu.edu.cn/showproblem.php?pid=1166贴个链接
比较纠结的是TLE了好几次。。原因居然是。。。。。*/
#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cmath>#include <cstring>#include <queue>#include <set>#include <vector>#include <stack>#include <map>#include <iomanip>#define PI acos(-1.0)#define Max 50005#define inf 1<<28using namespace std;int peonum,c[Max],m;int lowbit(int x){ return x&(-x);}void updata(int x,int y){ while(x<=m) { c[x]+=y; x+=lowbit(x); }}int query(int x){ int ans=0; while(x>0) { ans+=c[x]; x-=lowbit(x); } return ans;}int main(){ int i,j,k,l,n; char aa[10]; int x1,y1,s; int kk=0; scanf("%d",&n); while(n--) { printf("Case %d:\n",++kk); scanf("%d",&m); memset(c,0,sizeof(c)); for(i=1; i<=m; i++) scanf("%d",&peonum),updata(i,peonum); scanf("%s",aa); while(aa[0]!='E') { scanf("%d%d",&x1,&y1); if(aa[0]=='Q') { printf("%d\n",query(y1)-query(x1-1));//一开始没注意啊。直接写cout....然后各种TLE死都找不出哪里有问题。。随手换了个printf..就A了。。。 } else if(aa[0]=='A') { updata(x1,y1); } else { updata(x1,-y1); } scanf("%s",aa); } } return 0;}
还是有点粗心啊。。继续加油~
- HDU 1166 树状数组 基础题
- HDU-1541 树状数组(基础题)
- hdu 1166 树状数组
- hdu 1166(树状数组)
- HDU 1166树状数组
- HDU 1166 树状数组
- HDU 1166 树状数组
- HDU 1166 树状数组
- hdu 1166 树状数组
- HDU 1166 树状数组
- 树状数组 ( 基础篇 )——敌兵布阵 ( HDU 1166 )
- HDU 1166 敌兵布阵(树状数组,基础)
- hdu 1116 线段树或树状数组(基础题)
- hdu 1166 树状数组 入门题
- hdu 1166 树状数组简单题
- hdu 1166 树状数组模板题
- 简单基础树状数组 HDU 1556
- HDU-1166(树状数组入门)
- u-boot命令行接口
- oracle变量绑定
- 12 线性区的底层处理
- Oracle Data Types - NVARCHAR2 (zz)
- android定位功能
- HDU 1166 树状数组 基础题
- 13 分配线性地址区间
- 浅谈HTTP中Get与Post的区别
- Qt下 QString转char*
- 使用TextView/EditText应该注意的地方
- 14 释放线性地址区间
- DirectShow中网络播放器的源Source Filter
- 15 缺页异常处理程序
- 事件与委托的入门例子