diff options
author | Anthony Wang | 2020-07-17 23:02:06 -0500 |
---|---|---|
committer | Anthony Wang | 2020-07-17 23:02:06 -0500 |
commit | c7bf1734730ba95155a30457d735e4a0282e68a3 (patch) | |
tree | 3d4a82ce38e06ef0122d937665f99de140744953 | |
parent | 3014121f4d501983b8b81e855a85997991d30f2d (diff) |
Update fenwick_tree.cpp
-rw-r--r-- | Data Structures/fenwick_tree.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Data Structures/fenwick_tree.cpp b/Data Structures/fenwick_tree.cpp index aa87001..19120ab 100644 --- a/Data Structures/fenwick_tree.cpp +++ b/Data Structures/fenwick_tree.cpp @@ -1,8 +1,8 @@ template<typename T> class fenwick_tree { private: vector<T> FT; public: - fenwick_tree(int N) { FT.assign(N + 1, 0); } - void update(int x, T val) { if (x > 0) for (; x < FT.size(); x += x & -x) FT[x] += val; } - T query(int x) { T ret = 0; if (x > 0) for (; x > 0; x -= x & -x) ret += FT[x]; return ret; } + fenwick_tree(int N) { FT.assign(N + 5, 0); } + void update(int x, T val) { if (++x) for (; x < FT.size(); x += x & -x) FT[x] += val; } + T query(int x) { T ret = 0; if (++x) for (; x > 0; x -= x & -x) ret += FT[x]; return ret; } T query(int x, int y) { return query(y) - query(x - 1); } };
\ No newline at end of file |