知识点 - 树状数组
知识点 - 树状数组 解决问题类型: 单点更新,前缀查询,很简单地拓展到2维 复杂度即代码: //压行 #define lowbit(x) ((x)&(-(x))) void add(int x, int y) { for (; x <= idx; x += lowbit(x)) f[x] += y; } int sum(int x) { int ans = 0; for (; x; x -= lowbit(x)) ans += f[x]; return ans; } //从0开始的BIT(下标) struct FenwickTree { vector<int> bit; // binary indexed tree int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } FenwickTree(vector<int> a) : FenwickTree(a.size()) { for (size_t i = 0; i < a.size(); i++) add(i, a[i]); } int sum(int r) { int ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r]; return ret; } int sum(int l, int r)