diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-06-23 01:13:23 +0200 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-06-23 01:13:23 +0200 |
| commit | a6e8d68a9b406027f48fb81cae6cf13d073ffa5a (patch) | |
| tree | f80b7e855666a6e092534016972e97ee30a6e65e | |
| parent | 7f040b63d7581985b399d7eab1762b0951f49dde (diff) | |
simplify fenwick tree
| -rw-r--r-- | datastructures/fenwickTree.cpp | 2 | ||||
| -rw-r--r-- | datastructures/fenwickTree2.cpp | 4 |
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; } |
