hdu——1166(数据结构之树状数组的简单应用)
来源:互联网 发布:淘宝客营销计划条件 编辑:程序博客网 时间:2024/06/14 07:40
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1166
#include <iostream>#include <cmath>#include <string>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;typedef long long ll;#define INF 0xfffffff#define MAX(a,b) a>b?a:b#define MIN(a,b) a>b?b:a#define N 50005int c[N];int lowbit(int t){ return t&(-t);} void insert(int k,int d,int max){ while(k<=max) { c[k]+=d; k+=lowbit(k); }}int getsum(int k){ int t=0; while(k>0) //必须k>0,不能k为真。 { t+=c[k]; k-=lowbit(k); } return t;}char s[100];int main(){ int i,j,k,t; int m,n,num; cin>>t; int st,ed,position; for(i=1;i<=t;i++){memset(c,0,sizeof(c));cin>>n;for(j=1;j<=n;j++) { cin>>num; insert(j,num,n); } printf("Case %d:\n",i); while(cin>>s){ if(s[0]=='E') break; if(s[0]=='Q') { cin>>st>>ed; printf("%d\n",getsum(ed)-getsum(st-1)); } else if(s[0]=='S') { cin>>position>>num; insert(position,-1*num,n); } else { cin>>position>>num; insert(position,num,n); } }} return 0;}
- hdu——1166(数据结构之树状数组的简单应用)
- hdu(1166):敌兵布阵—树状数组的应用
- hdu 1166简单的树状数组
- hdu 5147 (树状数组的应用)
- HDU 1556 Color the ball (树状数组简单应用)
- hdu 3874 Necklace【树状数组简单应用】
- hdu 1541 Stars【树状数组简单应用】
- HDU 1541 Stars 树状数组简单应用
- 数据结构—树状数组
- 数据结构之树状数组
- 数据结构之树状数组
- 数据结构之树状数组
- 数据结构之树状数组
- 数据结构之树状数组
- 【数据结构之树状数组】
- 数据结构之树状数组
- 数据结构之树状数组
- 数据结构之树状数组
- VIM配置升级版
- 7-ZIP解压linux下的压缩包格式
- Hoj 2632 Blanks in a Table
- HDU 4648 Magic Pen 6
- To compile mplayer on Mac OS X
- hdu——1166(数据结构之树状数组的简单应用)
- HttpClient 入门
- 认识TCP/IP协议--简介
- C++ STL视频教程
- 如何去理解递归,想到递归,运用递归
- java服务器
- timus 1346. Intervals of Monotonicity URAL 解题报告 DP 小水题,阅读理解
- oracle decode函数使用方法
- Packet Sniffer Code in C using sockets