diff options
| author | Paul Jungeblut <paul.jungeblut@gmail.com> | 2016-09-16 11:28:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-16 11:28:47 +0200 |
| commit | 4228bab3c06b732c056fb8182534f6233cff415a (patch) | |
| tree | 6c9a3ad655c79d930d861b75197df6c8960700ab | |
| parent | 6679f0299d4d1a36b4fcda2de8c9c7065c7c9ba5 (diff) | |
| parent | f99e41c0a45ad2a9d7cf422fc0c65546c53da0b7 (diff) | |
Merge pull request #20 from CaptainDreamcast/patch-1
Update fenwickTree.cpp
| -rw-r--r-- | datastructures/fenwickTree.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/datastructures/fenwickTree.cpp b/datastructures/fenwickTree.cpp index 3b54fc9..cd30329 100644 --- a/datastructures/fenwickTree.cpp +++ b/datastructures/fenwickTree.cpp @@ -1,6 +1,11 @@ vector<int> FT; //Fenwick-Tree int n; +//Adds val to index i. Time Complexity O(log(n)) +void updateFT(int i, int val) { + i++; while(i <= n) { FT[i] += val; i += (i & (-i)); } +} + //Build an Fenwick-Tree over an array a. Time Complexity: O(n*log(n)) void buildFenwickTree(vector<int>& a) { n = a.size(); @@ -14,9 +19,3 @@ int prefix_sum(int i) { while(i > 0) { sum += FT[i]; i -= (i & (-i)); } return sum; } - -//Adds val to index i. Time Complexity O(log(n)) -void updateFT(int i, int val) { - i++; while(i <= n) { FT[i] += val; i += (i & (-i)); } -} - |
