formatting source-code for d7af6fdc8c

This commit is contained in:
github-actions
2020-05-29 23:26:30 +00:00
parent edb3d51ec2
commit 7ad1f171c1
176 changed files with 5342 additions and 4288 deletions

View File

@@ -7,22 +7,18 @@ class Bit
{
int n;
vector<int> bit;
inline int offset(int x)
inline int offset(int x) { return (x & (-x)); }
public:
Bit(vector<int>& arr)
{
return (x & (-x));
}
public:
Bit(vector<int>& arr)
{
n = arr.size();
bit.assign(n + 1, 0);
for (int i = 0; i < n; ++i)
{
update(i, arr[i]);
}
n = arr.size();
bit.assign(n + 1, 0);
for (int i = 0; i < n; ++i)
{
update(i, arr[i]);
}
}
Bit(int x)
{
n = x;
@@ -34,7 +30,7 @@ class Bit
// Add val at id
id++;
while (id <= n)
{
{
bit[id] += val;
id += offset(id);
}
@@ -46,23 +42,20 @@ class Bit
id++;
int res = 0;
while (id > 0)
{
{
res += bit[id];
id -= offset(id);
}
return res;
}
int sum_range(int l, int r)
{
return sum(r) - sum(l - 1);
}
int sum_range(int l, int r) { return sum(r) - sum(l - 1); }
};
int main()
{
int n = 5;
vector<int> arr = { 1, 2, 3, 4, 5 };
vector<int> arr = {1, 2, 3, 4, 5};
Bit x(arr);
assert(x.sum_range(0, 0) == 1);
@@ -72,5 +65,5 @@ int main()
assert(x.sum_range(0, 0) == 6);
assert(x.sum_range(0, 1) == 8);
assert(x.sum_range(0, 2) == 11);
return 0;
return 0;
}