summaryrefslogtreecommitdiff
path: root/datastructures
diff options
context:
space:
mode:
Diffstat (limited to 'datastructures')
-rw-r--r--datastructures/datastructures.tex4
-rw-r--r--datastructures/fenwickTree.cpp2
-rw-r--r--datastructures/fenwickTree2.cpp2
-rw-r--r--datastructures/test/fenwickTree.cpp4
-rw-r--r--datastructures/test/fenwickTree2.cpp4
5 files changed, 8 insertions, 8 deletions
diff --git a/datastructures/datastructures.tex b/datastructures/datastructures.tex
index 61f04ba..37a1dc2 100644
--- a/datastructures/datastructures.tex
+++ b/datastructures/datastructures.tex
@@ -17,14 +17,14 @@
\begin{algorithm}{Fenwick Tree}
\begin{methods}
\method{init}{baut den Baum auf}{n\*\log(n)}
- \method{prefix\_sum}{summe von [0, i]}{\log(n)}
+ \method{prefix\_sum}{summe von [0, i)}{\log(n)}
\method{update}{addiert ein Delta zu einem Element}{\log(n)}
\end{methods}
\sourcecode{datastructures/fenwickTree.cpp}
\begin{methods}
\method{init}{baut den Baum auf}{n\*\log(n)}
- \method{prefix\_sum}{summe von [0, i]}{\log(n)}
+ \method{prefix\_sum}{summe von [0, i)}{\log(n)}
\method{update}{addiert ein Delta zu allen Elementen [l, r)}{\log(n)}
\end{methods}
\sourcecode{datastructures/fenwickTree2.cpp}
diff --git a/datastructures/fenwickTree.cpp b/datastructures/fenwickTree.cpp
index cac3cf8..6c5ed91 100644
--- a/datastructures/fenwickTree.cpp
+++ b/datastructures/fenwickTree.cpp
@@ -10,6 +10,6 @@ void init(int n) {
ll prefix_sum(int i) {
ll sum = 0;
- for (i++; i > 0; i -= (i & (-i))) sum += tree[i];
+ for (; i > 0; i -= (i & (-i))) sum += tree[i];
return sum;
}
diff --git a/datastructures/fenwickTree2.cpp b/datastructures/fenwickTree2.cpp
index ff87e2e..43c3a32 100644
--- a/datastructures/fenwickTree2.cpp
+++ b/datastructures/fenwickTree2.cpp
@@ -14,7 +14,7 @@ void init(vector<ll>& v) {
}
ll prefix_sum (int i) {
- ll res = 0; i++;
+ ll res = 0;
for (int ti = i; ti > 0; ti -= ti&(-ti))
res += add[ti] * i + mul[ti];
return res;
diff --git a/datastructures/test/fenwickTree.cpp b/datastructures/test/fenwickTree.cpp
index 4bc812a..f9dd619 100644
--- a/datastructures/test/fenwickTree.cpp
+++ b/datastructures/test/fenwickTree.cpp
@@ -10,10 +10,10 @@ void test(int n) {
update(p, delta);
naive[p] += delta;
- int r = util::randint(n+1) - 1;
+ int r = util::randint(n+1);
ll naive_result = 0;
- for (int i = 0; i <= r; i++) naive_result += naive[i];
+ for (int i = 0; i < r; i++) naive_result += naive[i];
ll fenwick_result = prefix_sum(r);
assert(naive_result == fenwick_result);
}
diff --git a/datastructures/test/fenwickTree2.cpp b/datastructures/test/fenwickTree2.cpp
index 359a5c4..18ebcb7 100644
--- a/datastructures/test/fenwickTree2.cpp
+++ b/datastructures/test/fenwickTree2.cpp
@@ -12,10 +12,10 @@ void test(int n) {
update(l, r, delta);
for (int i = l; i < r; i++) naive[i] += delta;
- r = util::randint(n+1) - 1;
+ r = util::randint(n+1);
ll naive_result = 0;
- for (int i = 0; i <= r; i++) naive_result += naive[i];
+ for (int i = 0; i < r; i++) naive_result += naive[i];
ll fenwick_result = prefix_sum(r);
assert(naive_result == fenwick_result);
}