HDU 1166 敌兵布阵(树状数组)
来源:互联网 发布:mac上顿号怎么打 编辑:程序博客网 时间:2024/04/30 06:16
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=25681#problem/A
代码:
#include<stdio.h>#include<string.h>using namespace std;int a[50005],n;int lowbit(int t){ return t&(-t);}int insert(int t,int d){ while(t<=n) { a[t]=a[t]+d; t=t+lowbit(t); }}long long getsum(int t){ long long ans=0; while(t>0) { ans=ans+a[t]; t=t-lowbit(t); } return ans;}int main(){ int t,temp=0; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=1;i<=n;i++) { int k; scanf("%d",&k); insert(i,k); } char str[10]; printf("Case %d:\n",++temp); while(scanf("%s",str)&&(strcmp(str,"End")!=0)) { int x,y; scanf("%d%d",&x,&y); if(strcmp(str,"Query")==0) { printf("%d\n",getsum(y)-getsum(x-1)); } else if(strcmp(str,"Add")==0) { insert(x,y); } else if(strcmp(str,"Sub")==0) { insert(x,(-1)*y); } } }}
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(敌兵布阵)
- [整理]通过http1.1 GET, POST, PUT, PATCH, DELETE, HEAD, TRACE理解真正的RESTFUL
- android小知识——Android混淆打包及混淆后运行错误
- 淘宝数据抓取1.0-根据url抓取尺码和价格
- JSR-338 学习笔记(JPA)
- 部署 Bonobo Git Server 时,出现 HTTP 错误 500.19 解决办法
- HDU 1166 敌兵布阵(树状数组)
- Qt入门-文本框类QLineEdit和QTextEdit
- 349. Intersection of Two Arrays
- ngnix+tomcat简单的负载均衡
- Android小知识——关于引入第三方jar包引发的java.lang.NoClassDefFoun
- linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结
- cp直接覆盖不提示按Y/N的方法
- 自定义ListView侧滑删除 畅所欲滑,删你想删
- 配置apache的vhost出现的问题和解决方法。