summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--datastructures/fenwickTree.cpp6
-rw-r--r--datastructures/fenwickTree2.cpp14
-rw-r--r--datastructures/test/fenwickTree.cpp1
-rw-r--r--datastructures/test/fenwickTree2.cpp1
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) {