HDU1166 敌兵布阵(树状数组)
来源:互联网 发布:linux 电池 编辑:程序博客网 时间:2024/05/29 03:14
<pre name="code" class="cpp">/*树状数组太屌了,看了一天才模模糊糊看懂了这个题解然后自己敲了一遍,算是记住这个模板了附上原题解网址:http://gzhu-101majia.iteye.com/blog/1142115*/#include <cstdio>#include <cstring>using namespace std;int n,a[50000+5];char str[10];int lowbit(int i)//此处琢磨了许久,必须画图才能理解{ return i&(-i);}void update(int i,int val){ while(i<=n) { a[i]+=val; i+=lowbit(i); }}int sum(int i){ int s=0; while(i>0) { s+=a[i]; i-=lowbit(i); } return s;}int main(){ int t,val,cas=1,x,y; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { scanf("%d",&val); update(i,val); } printf("Case %d:\n",cas++); while(~scanf("%s",str)) { if(str[0]=='E') break; scanf("%d%d",&x,&y); if(str[0]=='A') update(x,y); else if(str[0]=='S') update(x,-y); else printf("%d\n",sum(y)-sum(x-1)); } } return 0;}
0 0
- hdu1166敌兵布阵(大意)树状数组
- HDU1166 敌兵布阵(树状数组)
- HDU1166 敌兵布阵(树状数组)
- HDU1166:敌兵布阵(树状数组)
- hdu1166 敌兵布阵(树状数组)
- (树状数组)hdu1166 敌兵布阵
- 【HDU1166】敌兵布阵(树状数组)
- 【HDU1166敌兵布阵](树状数组)
- hdu1166 敌兵布阵(树状数组)
- hdu1166-敌兵布阵-树状数组
- hdu1166 敌兵布阵 +树状数组
- hdu1166 敌兵布阵 (树状数组)
- hdu1166 敌兵布阵 树状数组
- HDU1166 敌兵布阵 【树状数组】
- hdu1166 敌兵布阵 树状数组
- HDu1166敌兵布阵(树状数组)
- hdu1166 敌兵布阵--树状数组
- HDU1166 敌兵布阵(树状数组)
- androidの当前时间动态显示
- Spring 注解学习手札(七) 补遗——@ResponseBody,@RequestBody,@PathVariable
- emcpy()和memmove()区别
- C++堆和栈的区别
- Mybatis 批量操作
- HDU1166 敌兵布阵(树状数组)
- 动态规划--数字三角形
- re2正则表达式引擎学习(一)
- poj 1625 AC自动机+动归+大数加法
- MySQL和MySQL Workbench连接
- 安全驾驶-车颜色与安全(二)
- 成员对象和封闭类
- 数据分析指标解析之一 DAU/MAU
- 第六章:提升感光效率什么方法强?Q-lens技术可帮忙