From a6e8d68a9b406027f48fb81cae6cf13d073ffa5a Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Sun, 23 Jun 2024 01:13:23 +0200 Subject: simplify fenwick tree --- datastructures/fenwickTree2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'datastructures/fenwickTree2.cpp') 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& v) { +void init(vector &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& 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; } -- cgit v1.2.3