diff --git a/fenwick.cpp b/fenwick.cpp new file mode 100644 index 0000000..8b60cb3 --- /dev/null +++ b/fenwick.cpp @@ -0,0 +1,13 @@ +typedef long long ll; +struct fenwick { + vector tree; + fenwick(int n) : tree(n + 1) {} + void update(int idx, int df) { + for (; idx < tree.size(); idx += idx & -idx) tree[idx] += df; + } + ll get_sum(int e) { + ll ret = 0; + for (; e > 0; e -= e & -e) ret += tree[e]; + return ret; + } +};