Skip to content

Commit

Permalink
[#14] style: apply format
Browse files Browse the repository at this point in the history
  • Loading branch information
kogetsu7 committed Jan 6, 2025
1 parent 3ab36bd commit 213a44a
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 57 deletions.
4 changes: 3 additions & 1 deletion data_structure/fenwick_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ template <class T> class FenwickTree {
FenwickTree() : FenwickTree(0) {}
FenwickTree(int _n) : n(_n), v(_n, T(0)) { assert(0 <= n); }
FenwickTree(const vector<T>& _v) : FenwickTree(_v.size()) {
rep(i, 0, _v.size()) { set(i, _v[i]); }
rep (i, 0, _v.size()) {
set(i, _v[i]);
}
}

T sum(int l, int r) const {
Expand Down
11 changes: 7 additions & 4 deletions data_structure/rollback_union_find.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RollbackUnionFind {
}

vector<int> x(2);
rep(i, 0, 2) {
rep (i, 0, 2) {
auto [v, p] = his.top();
his.pop();

Expand All @@ -80,7 +80,8 @@ class RollbackUnionFind {
}

void rollback() {
while (undo());
while (undo())
;

return;
}
Expand All @@ -89,9 +90,11 @@ class RollbackUnionFind {
vector<vector<int>> mem(n);
vector<vector<int>> res;

rep(i, 0, n) { mem[leader(i)].emplace_back(i); }
rep (i, 0, n) {
mem[leader(i)].emplace_back(i);
}

rep(i, 0, n) {
rep (i, 0, n) {
if (!mem[i].empty()) {
res.emplace_back(mem[i]);
}
Expand Down
8 changes: 6 additions & 2 deletions data_structure/segment_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ template <class S, S (*op)(S, S), S (*e)()> class SegmentTree {
SegmentTree() : SegmentTree(0) {}
SegmentTree(int _n) : SegmentTree(vector<S>(_n, e())) {}
SegmentTree(const vector<S>& _v) : n(int(_v.size())), v(_v.size() * 2, e()) {
rep(i, 0, n) { v[n + i] = _v[i]; }
rep (i, 0, n) {
v[n + i] = _v[i];
}

rrep(i, n - 1, 1) { update(i); }
rrep (i, n - 1, 1) {
update(i);
}
}

S get(int i) const { return v[i + n]; }
Expand Down
6 changes: 4 additions & 2 deletions data_structure/union_find.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class UnionFind {
vector<vector<int>> groups() {
vector<vector<int>> mem(n), res;

rep(i, 0, n) { mem[leader(i)].emplace_back(i); }
rep (i, 0, n) {
mem[leader(i)].emplace_back(i);
}

rep(i, 0, n) {
rep (i, 0, n) {
if (!mem[i].empty()) {
res.emplace_back(mem[i]);
}
Expand Down
6 changes: 4 additions & 2 deletions data_structure/weighted_union_find.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ template <class T> class WeightedUnionFind {
vector<vector<int>> groups() {
vector<vector<int>> mem(n), res;

rep(i, 0, n) { mem[leader(i)].push_back(i); }
rep (i, 0, n) {
mem[leader(i)].push_back(i);
}

rep(i, 0, n) {
rep (i, 0, n) {
if (!mem[i].empty()) {
res.push_back(mem[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions graph/topological_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class TopologicalSort {
init = true;

vector<int> cnt(n);
rep(v, 0, n) {
rep (v, 0, n) {
for (int nv : g[v]) {
cnt[nv]++;
}
}

queue<int> que;
rep(v, 0, n) {
rep (v, 0, n) {
if (cnt[v] == 0) {
que.emplace(v);
}
Expand Down
8 changes: 6 additions & 2 deletions math/binomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ template <class T> class Binomial {
assert(0 <= _n);

fact[0] = T(1);
rep(i, 0, n) { fact[i + 1] = fact[i] * T(i + 1); }
rep (i, 0, n) {
fact[i + 1] = fact[i] * T(i + 1);
}

ifact[n] = T(1) / fact[n];
rrep(i, n, 1) { ifact[i - 1] = ifact[i] * T(i); }
rrep (i, n, 1) {
ifact[i - 1] = ifact[i] * T(i);
}
}

//! 順列
Expand Down
10 changes: 6 additions & 4 deletions math/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ template <class T> class Matrix {
static Matrix identity(int s) {
Matrix res(s);

rep(i, 0, s) { res.set(i, i, T(1)); }
rep (i, 0, s) {
res.set(i, i, T(1));
}

return res;
}
Expand All @@ -42,9 +44,9 @@ template <class T> class Matrix {
assert(lhs.w == rhs.h);

Matrix res(lhs.h, rhs.w);
rep(i, 0, lhs.h) {
rep(j, 0, rhs.w) {
rep(k, 0, lhs.w) {
rep (i, 0, lhs.h) {
rep (j, 0, rhs.w) {
rep (k, 0, lhs.w) {
res.set(i, j, res.get(i, j) + lhs.get(i, k) * rhs.get(k, j));
}
}
Expand Down
6 changes: 3 additions & 3 deletions math/prime_sieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PrimeSieve {
public:
PrimeSieve() : PrimeSieve(0) {}
PrimeSieve(int _n) : div(_n + 1), pri(0) {
rep(i, 2, _n + 1) {
rep (i, 2, _n + 1) {
if (div[i] != 0) {
continue;
}
Expand Down Expand Up @@ -59,10 +59,10 @@ class PrimeSieve {
for (auto [p, q] : pf) {
int s = res.size();

rep(i, 0, s) {
rep (i, 0, s) {
int m = 1;

rep(j, 0, q) {
rep (j, 0, q) {
m *= p;
res.emplace_back(res[i] * m);
}
Expand Down
2 changes: 1 addition & 1 deletion string/rolling_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ template <class T> class RollingHash {
hash[0] = T(0);
pow[0] = T(1);

rep(i, 0, _s.length()) {
rep (i, 0, _s.length()) {
hash[i + 1] = hash[i] * _base + T(_s[i]);
pow[i + 1] = pow[i] * _base;
}
Expand Down
6 changes: 4 additions & 2 deletions test/data_structure/fenwick_tree.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ int main() {
cin >> N >> Q;

vector<ll> A(N);
rep(i, 0, N) { cin >> A[i]; }
rep (i, 0, N) {
cin >> A[i];
}

FenwickTree<ll> fw1(N);
FenwickTree<ll> fw2(N);
FenwickTree<ll> fw3(A);
rep(i, 0, N) {
rep (i, 0, N) {
fw1.add(i, A[i]);
fw2.set(i, A[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions test/data_structure/rollback_union_find.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {

vector<vector<int>> g(Q + 1);
vector<int> t(Q), k(Q), u(Q), v(Q);
rep(i, 0, Q) {
rep (i, 0, Q) {
cin >> t[i] >> k[i] >> u[i] >> v[i];
g[k[i] + 1].emplace_back(i + 1);
}
Expand Down Expand Up @@ -41,7 +41,7 @@ int main() {

dfs(dfs, 0);

rep(i, 0, Q) {
rep (i, 0, Q) {
if (t[i] == 1) {
cout << (ans[i] ? 1 : 0) << LF;
}
Expand Down
4 changes: 3 additions & 1 deletion test/data_structure/segment_tree.range_min.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ int main() {
int N, Q;
cin >> N >> Q;
vector<ll> A(N);
rep(i, 0, N) { cin >> A[i]; }
rep (i, 0, N) {
cin >> A[i];
}

SegmentTree<ll, op, e> seg(A);
while (Q--) {
Expand Down
8 changes: 4 additions & 4 deletions test/graph/topological_sort.get.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main() {
TopologicalSort ts(N);
TopologicalSort ts_inv(N);

rep(i, 0, M) {
rep (i, 0, M) {
int u, v, w;
cin >> u >> v >> w;

Expand All @@ -30,7 +30,7 @@ int main() {
vector<int> ep(N, INF<int>);
ep[0] = 0;

rep(i, 0, N) {
rep (i, 0, N) {
int v = ts.get(i);
for (auto [nv, co] : g[v]) {
dp[nv] = max(dp[nv], dp[v] + co);
Expand All @@ -39,15 +39,15 @@ int main() {

ep[N - 1] = dp[N - 1];

rep(i, 0, N) {
rep (i, 0, N) {
int v = ts_inv.get(i);
for (auto [nv, co] : g[v]) {
ep[v] = min(ep[v], ep[nv] - co);
}
}

int cnt = N;
rep(i, 0, N) {
rep (i, 0, N) {
if (dp[i] == ep[i]) {
cnt--;
}
Expand Down
2 changes: 1 addition & 1 deletion test/graph/topological_sort.is_dag.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {
cin >> N >> M;

TopologicalSort ts(N);
rep(i, 0, M) {
rep (i, 0, M) {
int u, v;
cin >> u >> v;

Expand Down
8 changes: 4 additions & 4 deletions test/math/matrix.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ int main() {

vector A(N, std::vector<StaticModInt<998244353>>(N));
Matrix<StaticModInt<998244353>> mat(N);
rep(i, 0, N) {
rep(j, 0, N) {
rep (i, 0, N) {
rep (j, 0, N) {
ll a;
cin >> a;

Expand All @@ -23,8 +23,8 @@ int main() {

mat = mat.pow(K);

rep(i, 0, N) {
rep(j, 0, N) {
rep (i, 0, N) {
rep (j, 0, N) {
if (0 < j) {
cout << ' ';
}
Expand Down
2 changes: 1 addition & 1 deletion test/math/prime_sieve.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main() {
PrimeSieve ps(N);

int ans = 0;
rep(i, 2, N + 1) {
rep (i, 2, N + 1) {
auto pf = ps.get_prime_factors(i);

if (K <= int(pf.size())) {
Expand Down
6 changes: 4 additions & 2 deletions test/other/next_combination.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ int main() {
int N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, 0, N) { cin >> A[i]; }
rep (i, 0, N) {
cin >> A[i];
}

vector<int> id(N);
iota(all(id), 0);

int ans = 0;
do {
ll s1 = 0, s2 = 0;
rep(i, 0, K) {
rep (i, 0, K) {
s1 = (s1 + A[id[i]]) % 998;
s2 = (s2 + A[id[i]]) % 998244353;
}
Expand Down
4 changes: 2 additions & 2 deletions test/string/rolling_hash.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main() {

vector<int> ans(N);

rep(i, 0, N) {
rep (i, 0, N) {
auto check = [&](int m) -> bool {
if (rh1.get(0, m) != rh1.get(i, i + m)) {
return false;
Expand All @@ -45,7 +45,7 @@ int main() {
ans[i] = ok;
}

rep(i, 0, N) {
rep (i, 0, N) {
if (0 < i) {
cout << ' ';
}
Expand Down
Loading

0 comments on commit 213a44a

Please sign in to comment.