From f99e41c0a45ad2a9d7cf422fc0c65546c53da0b7 Mon Sep 17 00:00:00 2001 From: Josh Tari Date: Fri, 16 Sep 2016 11:28:09 +0200 Subject: Update fenwickTree.cpp Verschieben update an richtige Stelle --- datastructures/fenwickTree.cpp | 11 +++++------ 1 file 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 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& 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)); } -} - -- cgit v1.2.3