summaryrefslogtreecommitdiff
path: root/datastructures
diff options
context:
space:
mode:
Diffstat (limited to 'datastructures')
-rw-r--r--datastructures/fenwickTree.cpp2
-rw-r--r--datastructures/fenwickTree2.cpp4
2 files changed, 3 insertions, 3 deletions
diff --git a/datastructures/fenwickTree.cpp b/datastructures/fenwickTree.cpp
index 8c73b78..7013613 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 > 0; i -= i & -i) sum += tree[i];
+ for (; i > 0; i &= i-1) sum += tree[i];
return sum;
}
diff --git a/datastructures/fenwickTree2.cpp b/datastructures/fenwickTree2.cpp
index 086e785..7fcdbb9 100644
--- a/datastructures/fenwickTree2.cpp
+++ b/datastructures/fenwickTree2.cpp
@@ -7,7 +7,7 @@ void update(int l, int r, ll val) {
add[tr] -= val, mul[tr] += val * r;
}
-void init(vector<ll>& v) {
+void init(vector<ll> &v) {
mul.assign(size(v) + 1, 0);
add.assign(size(v) + 1, 0);
for(int i = 0; i < ssize(v); i++) update(i, i + 1, v[i]);
@@ -15,7 +15,7 @@ void init(vector<ll>& v) {
ll prefix_sum(int i) {
ll res = 0;
- for (int ti = i; ti > 0; ti -= ti & -ti)
+ for (int ti = i; ti > 0; ti &= ti-1)
res += add[ti] * i + mul[ti];
return res;
}