Skip to content

Commit e212976

Browse files
committed
chore: ensure any class can initialize with no parameters
1 parent bf666f7 commit e212976

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/alfred/data_structure/dsu/cancel-dsu.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ class CancelDSU {
99
std::vector<int> fa, siz, S;
1010

1111
public:
12+
CancelDSU(void) = default;
1213
CancelDSU(int n) : fa(n + 1), siz(n + 1, 1) {
1314
std::iota(fa.begin(), fa.end(), 0);
1415
}
16+
inline void init(int n) {
17+
n++, fa.resize(n), siz.assign(n, 1);
18+
std::iota(fa.begin(), fa.end(), 0);
19+
}
1520
inline int find(int x) {
1621
return fa[x] == x ? x : find(fa[x]);
1722
}

src/alfred/data_structure/dsu/dsu.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66

77
struct DSU {
88
std::vector<int> fa, siz;
9+
DSU(void) = default;
910
DSU(int n) : fa(n + 1), siz(n + 1, 1) {
1011
std::iota(fa.begin(), fa.end(), 0);
1112
}
13+
inline void init(int n) {
14+
n++, fa.resize(n), siz.assign(n, 1);
15+
std::iota(fa.begin(), fa.end(), 0);
16+
}
1217
inline int find(int x) {
1318
return fa[x] == x ? x : fa[x] = find(fa[x]);
1419
}

src/alfred/data_structure/dsu/weighted-dsu.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ template <class T>
88
struct WeightedDSU {
99
std::vector<int> fa;
1010
std::vector<T> w;
11+
WeightedDSU(void) = default;
1112
WeightedDSU(int n) : fa(n + 1), w(n + 1) {
1213
std::iota(fa.begin(), fa.end(), 0);
1314
}
15+
inline void init(int n) {
16+
n++, fa.resize(n), w.resize(n);
17+
std::iota(fa.begin(), fa.end(), 0);
18+
}
1419
inline int find(int x) {
1520
if (fa[x] == x) return x;
1621
int f = fa[x], f2 = find(f);

src/alfred/data_structure/fenwick.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@
55

66
template <class T>
77
struct Fenwick {
8+
int n;
89
std::vector<T> c;
10+
Fenwick(void) = default;
11+
Fenwick(int len) : n(len + 2), c(len + 2) {}
12+
inline void init(int _n) { n = _n + 2, c.resize(n); }
913
inline int lowbit(int x) { return x & -x; }
1014
inline void merge(T &x, T &y) { x = x + y; }
1115
inline T subtract(T x, T y) { return x - y; }
12-
inline void update(size_t pos, T x) {
13-
for (pos++; pos < c.size(); pos += lowbit(pos)) merge(c[pos], x);
16+
inline void update(int pos, T x) {
17+
for (pos++; pos < n; pos += lowbit(pos)) merge(c[pos], x);
1418
}
1519
inline void clear(void) {
1620
for (auto &x : c) x = T();
1721
}
18-
inline T query(size_t pos) {
22+
inline T query(int pos) {
1923
T ans = T();
2024
for (pos++; pos; pos ^= lowbit(pos)) merge(ans, c[pos]);
2125
return ans;
2226
}
23-
inline T query(size_t l, size_t r) {
24-
return l == 0 ? query(r) : subtract(query(r), query(l - 1));
27+
inline T query(int l, int r) {
28+
return subtract(query(r), query(l - 1));
2529
}
2630
inline int kth(T k) {
2731
int ans = 0;
@@ -32,7 +36,6 @@ struct Fenwick {
3236
}
3337
return ans;
3438
}
35-
Fenwick(size_t len) : c(len + 2) {}
3639
};
3740

3841
#endif // AFDS_FENWICK

0 commit comments

Comments
 (0)