Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
spirit of modern C++
  • Loading branch information
alantudyk committed Oct 2, 2023
commit e56e39dc5e7ab767092f4993ced113202f4dce61
6 changes: 4 additions & 2 deletions atcoder/fenwicktree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ template <class T> struct fenwick_tree {
public:
fenwick_tree() : _n(0) {}
explicit fenwick_tree(int n) : _n(n), data(n) {}
explicit fenwick_tree(const std::vector<T> &v) : _n(v.size()), data(v.size()) {
explicit fenwick_tree(const T *const a, const int len) : fenwick_tree(len) {
U p = 0;
int i, j = -1;
while (++j < _n)
data[j] = p += U(v[j]);
data[j] = p += U(a[j]);
while (--j > 1)
if ((i = j & (j + 1)) > 0)
data[j] -= data[i - 1];
}
explicit fenwick_tree(const std::vector<T> &v) :
fenwick_tree(v.data(), int(v.size())) {}

void add(int p, T x) {
assert(0 <= p && p < _n);
Expand Down