树状数组
来源:互联网 发布:c语言心型示爱代码 编辑:程序博客网 时间:2024/05/02 01:51
ACM模版
一维
/* * INIT: ar[]置为0; * CALL: add(i, v): 将i点的值加v; sum(i): 求[1, i]的和; */const int N = 1010;#define typev int // type of restypev ar[N]; // index: 1 ~ Nint lowb(int t){ return t & (-t);}void add(int i, typev v){ for ( ; i < N; ar[i] += v, i += lowb(i)); return ;}typev sum(int i){ typev s = 0; for (; i > 0; s += ar[i], i -= lowb(i)); return s;}
二维
/* * INIT: c[][]置为0; Row,Col要赋初值 */const int N = 10000;int c[N][N];int Row, Col;inline int Lowbit(const int &x){ // x > 0 return x & (-x);}int Sum(int i, int j){ int tempj, sum = 0; while (i > 0) { tempj = j; while (tempj > 0) { sum += c[i][tempj]; tempj -= Lowbit(tempj); } i -= Lowbit(i); } return sum;}void Update(int i, int j, int num){ int tempj; while (i <= Row) { tempj = j; while (tempj <= Col) { c[i][tempj] += num; tempj += Lowbit(tempj); } i += Lowbit(i); } return ;}
0 0
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- HTTP状态码详解
- 二分查找
- LeetCode--No.110--Balanced Binary Tree--待完善
- Codeforces Round #325 (Div. 2)ABC
- LeetCode--No.235--Lowest Common Ancestor of a Binary Search Tree
- 树状数组
- wordpress数据库配置文件wp-config.php
- Spark小象学院笔记
- Android学习笔记3-绘图,双缓冲机制
- LintCode_512 Decode Ways
- Copy List with Random Pointer
- 2D Fast Marching Computations
- [leetcode] 376. Wiggle Subsequence 解题报告
- C++任务队列与多线程