二叉索引树(树状数组)
2016-05-02 11:48
267 查看
BIT标准用法:动态修改元素或求前缀和
例题:http://cojs.tk/cogs/problem/problem.php?pid=1316
例题:http://cojs.tk/cogs/problem/problem.php?pid=1316
//inline int lowbit(int x) { return x&(x^(x-1)); } inline int lowbit(int x) { return x&-x; } struct FenwickTree { int n; vector<int> C; void resize(int n) { this->n = n; C.resize(n); } void clear() { fill(C.begin(), C.end(), 0); } // 计算A[1]+A[2]+...+A[x] (x<=n) int sum(int x) { int ret = 0; while(x > 0) { ret += C[x]; x -= lowbit(x); } return ret; } // A[x] += d (1<=x<=n) void add(int x, int d) { while(x <= n) { C[x] += d; x += lowbit(x); } } };
相关文章推荐
- PHP变量的定义与相应的数据类型
- PHP变量的定义与相应的数据类型
- PHP变量的定义与相应的数据类型
- C经典 指针数组与二维数组指针变量的区别
- HDU-ACM2083
- HDU-ACM2081
- http协议学习笔记(四)
- 任务和特权级保护(一)——《x86汇编语言:从实模式到保护模式》读书笔记27
- 4 C 语言 数值存储方式 数组
- [leetcode] 347. Top K Frequent Elements 解题报告
- 2016.05工作日志
- 差分约束系统
- HDU-ACM2076
- 【NOIP 2013 DAY.1】T1 转圈游戏【codevs 3285】
- 《Nodejs开发加密货币》之六:Commander介绍
- mac下find: -exec: no terminating ";" or "+"的解决方法
- VMware下 Ubuntu 看不到共享文件夹之解决办法
- 快稳炫:电商峰值系统架构三字诀
- 快稳炫:电商峰值系统架构三字诀
- tornado用户指引(五)------- 一个并发的web爬虫