HDU 1166 树状数组
来源:互联网 发布:java技术的web服务器 编辑:程序博客网 时间:2024/05/29 15:05
题解:
关于树状数组:树状数组
AC code:
//lrl's submission#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cctype>#include<vector>#include<map>#include<cmath>#include<queue>#include<stack>#include<iostream>using namespace std;#define lowbit(x) (x & (-x))#define debug 0#define inf 0x3f3f3f3f#define M(a, b) memset(a, b, sizeof(a))const int maxn = 50000 + 5;int sum[maxn], a, b; //四倍空间int n;void query(int l, int r) { int la = 0, ra = 0; l--; while (l) { la += sum[l]; l -= lowbit(l); } while (r) { ra += sum[r]; r -= lowbit(r); } printf("%d\n", ra - la);}void Add(int i, int a) { while (i <= n) { sum[i] += a; i += lowbit(i); }}int main(){#if debug freopen("in.txt", "r", stdin);#endif // debug int t; scanf("%d", &t); char s[10]; for (int kase = 1; kase <= t; kase++) { printf("Case %d:\n", kase); M(sum, 0); //build(); scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a); Add(i, a); } while (~scanf("%s", s)) { if (s[0] == 'E') break; scanf("%d%d", &a, &b); if (s[0] == 'A') { Add(a, b); } if (s[0] == 'S') { Add(a, -b); } if (s[0] == 'Q') { query(a, b); } } } return 0;}
summary
cin, cout TLE +1
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 敌兵布阵【树状数组】
- 一个Android工程依赖了一个有 AndroidManifest.xml出现的错误
- delete 操作符 删除对像属性及相关知识
- 解决mysql导入脚本过大及超时的办法
- Openstack组件部署 — 将一个自定义 Service 添加到 Keystone
- blender模型导入unity项目报错
- HDU 1166 树状数组
- 字符指针 和 字符数组的区别
- 零基础入门 Docker
- STM32的TIM1_CH1N反向引脚输出PWM波.txt
- java继承
- Jsp 中文乱码解决
- 我的caffe学习之路<第八天>
- 二叉树的遍历——c语言
- rem布局下使用背景图片和sprite图