aboutsummaryrefslogtreecommitdiff
path: root/Data Structures
diff options
context:
space:
mode:
authorTa180m2019-09-16 22:08:32 -0500
committerTa180m2019-09-16 22:08:32 -0500
commit2c3db2a92acee49f2d353ae838ccdd9ad1587e42 (patch)
tree78d333cbf50fef569e3241094320131c5f46501a /Data Structures
parent12181073dbbd4a3d7acc94695dc3525020a5ac03 (diff)
Updated libaries
Diffstat (limited to 'Data Structures')
-rw-r--r--Data Structures/fenwick_tree.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Data Structures/fenwick_tree.cpp b/Data Structures/fenwick_tree.cpp
index e36e798..4bd7354 100644
--- a/Data Structures/fenwick_tree.cpp
+++ b/Data Structures/fenwick_tree.cpp
@@ -1,8 +1,8 @@
-class fenwick_tree {
-private: vector<int> FT;
+template<typename T> class fenwick_tree {
+private: vector<T> FT;
public:
fenwick_tree(int N) { FT.assign(N + 1, 0); }
- void update(int x, int val) { for (; x < FT.size(); x += x & -x) FT[x] += val; }
- int query(int x) { int ret = 0; if (x > 0) for (; x > 0; x -= x & -x) ret += FT[x]; return ret; }
- int query(int x, int y) { return query(y) - (x == 1 ? 0 : query(x - 1)); }
+ 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; }
+ T query(int x, int y) { return query(y) - (x == 1 ? 0 : query(x - 1)); }
}; \ No newline at end of file