diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-05-02 22:18:05 +0200 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-05-02 22:18:05 +0200 |
| commit | 2ff696b7a72f484f435ffc37dcacedb6fa434b3b (patch) | |
| tree | cae8bed3e7fecb61f6d0aec582bea5466ea5939b | |
| parent | 2ecbcca9952475c40bfd2a936b7631b236dfc922 (diff) | |
remove sz() from Fenwick trees
| -rw-r--r-- | datastructures/fenwickTree.cpp | 6 | ||||
| -rw-r--r-- | datastructures/fenwickTree2.cpp | 14 | ||||
| -rw-r--r-- | datastructures/test/fenwickTree.cpp | 1 | ||||
| -rw-r--r-- | datastructures/test/fenwickTree2.cpp | 1 |
4 files changed, 10 insertions, 12 deletions
diff --git a/datastructures/fenwickTree.cpp b/datastructures/fenwickTree.cpp index 6c5ed91..8c73b78 100644 --- a/datastructures/fenwickTree.cpp +++ b/datastructures/fenwickTree.cpp @@ -1,15 +1,15 @@ vector<ll> tree; void update(int i, ll val) { - for (i++; i < sz(tree); i += (i & (-i))) tree[i] += val; + for (i++; i < ssize(tree); i += i & -i) tree[i] += val; } void init(int n) { - tree.assign(n + 1,0); + tree.assign(n + 1, 0); } ll prefix_sum(int i) { ll sum = 0; - for (; 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 43c3a32..086e785 100644 --- a/datastructures/fenwickTree2.cpp +++ b/datastructures/fenwickTree2.cpp @@ -1,21 +1,21 @@ vector<ll> add, mul; void update(int l, int r, ll val) { - for (int tl = l + 1; tl < sz(add); tl += tl&(-tl)) + for (int tl = l + 1; tl < ssize(add); tl += tl & -tl) add[tl] += val, mul[tl] -= val * l; - for (int tr = r + 1; tr < sz(add); tr += tr&(-tr)) + for (int tr = r + 1; tr < ssize(add); tr += tr & -tr) add[tr] -= val, mul[tr] += val * r; } void init(vector<ll>& v) { - mul.assign(sz(v) + 1,0); - add.assign(sz(v) + 1,0); - for(int i = 0; i < sz(v); i++) update(i, i + 1, v[i]); + 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]); } -ll prefix_sum (int i) { +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 & -ti) res += add[ti] * i + mul[ti]; return res; } diff --git a/datastructures/test/fenwickTree.cpp b/datastructures/test/fenwickTree.cpp index 4c9695f..f9dd619 100644 --- a/datastructures/test/fenwickTree.cpp +++ b/datastructures/test/fenwickTree.cpp @@ -1,4 +1,3 @@ -#define sz ssize #include "../fenwickTree.cpp" void test(int n) { diff --git a/datastructures/test/fenwickTree2.cpp b/datastructures/test/fenwickTree2.cpp index 3567b05..18ebcb7 100644 --- a/datastructures/test/fenwickTree2.cpp +++ b/datastructures/test/fenwickTree2.cpp @@ -1,4 +1,3 @@ -#define sz ssize #include "../fenwickTree2.cpp" void test(int n) { |
