Skip to content

Commit 64ad942

Browse files
committed
format
1 parent d26afaa commit 64ad942

File tree

169 files changed

+3382
-3531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+3382
-3531
lines changed

.clang-format

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AllowShortBlocksOnASingleLine: Always
1313
AllowShortCaseLabelsOnASingleLine: true
1414
AllowShortEnumsOnASingleLine: true
1515
AllowShortFunctionsOnASingleLine: All
16-
AllowShortIfStatementsOnASingleLine: Always
16+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
1717
AllowShortLambdasOnASingleLine: All
1818
AllowShortLoopsOnASingleLine: true
1919
AlwaysBreakAfterReturnType: None
@@ -23,7 +23,7 @@ AttributeMacros: []
2323
BinPackArguments: true
2424
BinPackParameters: true
2525
BitFieldColonSpacing: Both
26-
BreakBeforeBinaryOperators: NonAssignment
26+
BreakBeforeBinaryOperators: None
2727
BreakBeforeBraces: Attach
2828
BreakBeforeConceptDeclarations: false
2929
BreakBeforeTernaryOperators: true
@@ -38,6 +38,8 @@ ConstructorInitializerIndentWidth: 2
3838
ContinuationIndentWidth: 2
3939
Cpp11BracedListStyle: true
4040
DerivePointerAlignment: true
41+
EmptyLineAfterAccessModifier: Never
42+
EmptyLineBeforeAccessModifier: Never
4143
FixNamespaceComments: false
4244
ForEachMacros: []
4345
IncludeBlocks: Preserve
@@ -47,18 +49,26 @@ IndentGotoLabels: false
4749
IndentWidth: 2
4850
IndentWrappedFunctionNames: false
4951
InsertTrailingCommas: None
52+
# LambdaBodyIndentation: OuterScope
5053
KeepEmptyLinesAtTheStartOfBlocks: false
5154
MaxEmptyLinesToKeep: 0
5255
NamespaceIndentation: None
56+
PackConstructorInitializers: BinPack
5357
PenaltyBreakAssignment: 1
5458
PenaltyBreakBeforeFirstCallParameter: 1
5559
PenaltyBreakComment: 300
56-
PenaltyBreakFirstLessLess: 120
60+
PenaltyBreakFirstLessLess: 1
61+
PenaltyBreakOpenParenthesis: 1
5762
PenaltyBreakString: 1000
5863
PenaltyExcessCharacter: 1000000
64+
# PenaltyIndentedWhitespace: 1000
5965
PenaltyReturnTypeOnItsOwnLine: 200
6066
PointerAlignment: Left
67+
# QualifierAlignment: Left
6168
ReflowComments: false
69+
ReferenceAlignment: Pointer
70+
RemoveBracesLLVM: true
71+
SeparateDefinitionBlocks: Never
6272
SortIncludes: false
6373
SortUsingDeclarations: false
6474
SpaceAfterCStyleCast: false
@@ -70,7 +80,7 @@ SpaceBeforeCaseColon: false
7080
SpaceBeforeCpp11BracedList: false
7181
SpaceBeforeCtorInitializerColon: false
7282
SpaceBeforeInheritanceColon: false
73-
SpaceBeforeParens: ControlStatements
83+
SpaceBeforeParens: ControlStatementsExceptControlMacros
7484
SpaceBeforeRangeBasedForLoopColon: true
7585
SpaceBeforeSquareBrackets: false
7686
SpaceInEmptyBlock: false

content/combinatorial/IntPerm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* Time: O(n)
88
*/
99
#pragma once
10-
1110
int permToInt(vi& v) {
1211
int use = 0, i = 0, r = 0;
13-
for(int x:v) r = r * ++i + __builtin_popcount(use & -(1<<x)),
14-
use |= 1 << x; // (note: minus, not ~!)
12+
for (int x : v)
13+
r = r * ++i + __builtin_popcount(use & -(1 << x)),
14+
use |= 1 << x; // (note: minus, not ~!)
1515
return r;
1616
}

content/combinatorial/binomialModPrime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
* Time: O(\log_p n)
1212
*/
1313
#pragma once
14-
1514
ll chooseModP(ll n, ll m, int p, vi& fact, vi& invfact) {
1615
ll c = 1;
1716
while (n || m) {
1817
ll a = n % p, b = m % p;
1918
if (a < b) return 0;
2019
c = c * fact[a] % p * invfact[b] % p * invfact[a - b] % p;
21-
n /= p; m /= p;
20+
n /= p, m /= p;
2221
}
2322
return c;
2423
}
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
int factmod(int n, int p) {
2-
vector<int> f(p);
3-
f[0] = 1;
4-
for (int i = 1; i < p; i++)
5-
f[i] = f[i-1] * i % p;
6-
7-
int res = 1;
8-
while (n > 1) {
9-
if ((n/p) % 2)
10-
res = p - res;
11-
res = res * f[n%p] % p;
12-
n /= p;
13-
}
14-
return res;
2+
vector<int> f(p);
3+
f[0] = 1;
4+
for (int i = 1; i < p; i++) f[i] = f[i - 1] * i % p;
5+
int res = 1;
6+
while (n > 1) {
7+
if ((n / p) % 2) res = p - res;
8+
res = res * f[n % p] % p;
9+
n /= p;
10+
}
11+
return res;
1512
}
16-
1713
int multiplicityFactorial(int n, int p) {
18-
int count = 0;
19-
do {
20-
n /= p;
21-
count += n;
22-
} while (n);
23-
return count;
14+
int count = 0;
15+
do {
16+
n /= p;
17+
count += n;
18+
} while (n);
19+
return count;
2420
}

content/combinatorial/multinomial.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
* Status: Tested on kattis:lexicography
77
*/
88
#pragma once
9-
109
ll multinomial(vi& v) {
1110
ll c = 1, m = v.empty() ? 1 : v[0];
12-
rep(i,1,sz(v)) rep(j,0,v[i])
13-
c = c * ++m / (j+1);
11+
rep(i, 1, sz(v)) rep(j, 0, v[i]) c = c * ++m / (j + 1);
1412
return c;
1513
}

content/combinatorial/schreier-sims.cpp

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,56 @@
33
* Description: Check group membership of permutation groups
44
*/
55
struct Perm {
6-
int a[N];
7-
Perm() {
8-
for (int i = 1; i <= n; ++i) a[i] = i;
9-
}
10-
friend Perm operator* (const Perm &lhs, const Perm &rhs) {
11-
static Perm res;
12-
for (int i = 1; i <= n; ++i) res.a[i] = lhs.a[rhs.a[i]];
13-
return res;
14-
}
15-
friend Perm inv(const Perm &cur) {
16-
static Perm res;
17-
for (int i = 1; i <= n; ++i) res.a[cur.a[i]] = i;
18-
return res;
19-
}
6+
int a[N];
7+
Perm() {
8+
for (int i = 1; i <= n; ++i) a[i] = i;
9+
}
10+
friend Perm operator*(const Perm &lhs, const Perm &rhs) {
11+
static Perm res;
12+
for (int i = 1; i <= n; ++i) res.a[i] = lhs.a[rhs.a[i]];
13+
return res;
14+
}
15+
friend Perm inv(const Perm &cur) {
16+
static Perm res;
17+
for (int i = 1; i <= n; ++i) res.a[cur.a[i]] = i;
18+
return res;
19+
}
2020
};
2121
class Group {
22-
bool flag[N];
23-
Perm w[N];
24-
std::vector<Perm> x;
22+
bool flag[N];
23+
Perm w[N];
24+
std::vector<Perm> x;
2525
public:
26-
void clear(int p) {
27-
memset(flag, 0, sizeof flag);
28-
for (int i = 1; i <= n; ++i) w[i] = Perm();
29-
flag[p] = true;
30-
x.clear();
31-
}
32-
friend bool check(const Perm&, int);
33-
friend void insert(const Perm&, int);
34-
friend void updateX(const Perm&, int);
26+
void clear(int p) {
27+
memset(flag, 0, sizeof flag);
28+
for (int i = 1; i <= n; ++i) w[i] = Perm();
29+
flag[p] = true;
30+
x.clear();
31+
}
32+
friend bool check(const Perm &, int);
33+
friend void insert(const Perm &, int);
34+
friend void updateX(const Perm &, int);
3535
} g[N];
3636
bool check(const Perm &cur, int k) {
37-
if (!k) return true;
38-
int t = cur.a[k];
39-
return g[k].flag[t] ? check(g[k].w[t] * cur, k - 1) : false;
37+
if (!k) return true;
38+
int t = cur.a[k];
39+
return g[k].flag[t] ? check(g[k].w[t] * cur, k - 1) : false;
4040
}
41-
void updateX(const Perm&, int);
41+
void updateX(const Perm &, int);
4242
void insert(const Perm &cur, int k) {
43-
if (check(cur, k)) return;
44-
g[k].x.push_back(cur);
45-
for (int i = 1; i <= n; ++i) if (g[k].flag[i]) updateX(cur * inv(g[k].w[i]), k);
43+
if (check(cur, k)) return;
44+
g[k].x.push_back(cur);
45+
for (int i = 1; i <= n; ++i)
46+
if (g[k].flag[i]) updateX(cur * inv(g[k].w[i]), k);
4647
}
4748
void updateX(const Perm &cur, int k) {
48-
int t = cur.a[k];
49-
if (g[k].flag[t]) {
50-
insert(g[k].w[t] * cur, k - 1);
51-
} else {
52-
g[k].w[t] = inv(cur);
53-
g[k].flag[t] = true;
54-
for (int i = 0; i < g[k].x.size(); ++i) updateX(g[k].x[i] * cur, k);
55-
}
49+
int t = cur.a[k];
50+
if (g[k].flag[t]) {
51+
insert(g[k].w[t] * cur, k - 1);
52+
} else {
53+
g[k].w[t] = inv(cur);
54+
g[k].flag[t] = true;
55+
for (int i = 0; i < g[k].x.size(); ++i)
56+
updateX(g[k].x[i] * cur, k);
57+
}
5658
}

content/contest/template.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#include <bits/stdc++.h>
22
using namespace std;
3-
4-
#define rep(i, a, b) for(int i = a; i < (b); ++i)
3+
#define rep(i, a, b) for (int i = a; i < (b); ++i)
54
#define all(x) begin(x), end(x)
65
#define sz(x) (int)(x).size()
76
using ll = long long;
87
using pii = pair<int, int>;
98
using vi = vector<int>;
10-
119
int main() {
12-
cin.tie(0)->sync_with_stdio(0);
13-
cin.exceptions(cin.failbit);
10+
cin.tie(0)->sync_with_stdio(0);
11+
cin.exceptions(cin.failbit);
1412
}

content/data-structures/HashMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct chash { // large odd number for C
1515
return __builtin_bswap64(x * C);
1616
}
1717
};
18-
__gnu_pbds::gp_hash_table<ll, int, chash> h(
19-
{}, {}, {}, {}, {1 << 16});
18+
__gnu_pbds::gp_hash_table<ll, int, chash> h({}, {}, {}, {},
19+
{1 << 16});
2020
template<class T> // for auto resize
2121
using hash_map = __gnu_pbds::gp_hash_table<ll, T, chash>;
Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
template<class T, T (*e)(), T (*op)(T, T),
2-
class F, F (*id)(), T (*onto)(F, T), F (*comp)(F, F)>
1+
template<class T, T (*e)(), T (*op)(T, T), class F, F (*id)(),
2+
T (*onto)(F, T), F (*comp)(F, F)>
33
struct lazy_segtree {
4-
int N, log, S;
5-
vector<T> d;
6-
vector<F> lz;
7-
lazy_segtree(const vector<T>& v): N(sz(v)), log(__lg(2*N-1)),
8-
S(1 << log), d(2*S, e()), lz(S, id()) {
9-
for (int i = 0; i < N; i++) d[S + i] = v[i];
10-
for (int i = S - 1; i >= 1; i--) pull(i);
11-
}
12-
void apply(int k, F f) {
13-
d[k] = onto(f, d[k]);
14-
if (k < S) lz[k] = comp(f, lz[k]);
15-
}
16-
void push(int k) {
17-
apply(2*k, lz[k]), apply(2*k+1, lz[k]), lz[k] = id();
18-
}
19-
void push(int l, int r) {
20-
int zl = __builtin_ctz(l), zr = __builtin_ctz(r);
21-
for (int i = log; i > min(zl, zr); i--) {
22-
if (i > zl) push(l >> i);
23-
if (i > zr) push((r - 1) >> i);
24-
}
25-
}
26-
void pull(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
27-
void set(int p, T x) {
28-
p += S;
29-
for (int i = log; i >= 1; i--) push(p >> i);
30-
for (d[p] = x; p /= 2; ) pull(p);
31-
}
32-
T query(int l, int r) {
33-
if (l == r) return T{};
34-
push(l += S, r += S);
35-
T vl = e(), vr = e();
36-
for (; l < r; l /= 2, r /= 2) {
37-
if (l & 1) vl = op(vl, d[l++]);
38-
if (r & 1) vr = op(d[--r], vr);
39-
}
40-
return op(vl, vr);
41-
}
42-
void update(int l, int r, F f) {
43-
if (l == r) return;
44-
push(l += S, r += S);
45-
for (int a = l, b = r; a < b; a /= 2, b /= 2) {
46-
if (a & 1) apply(a++, f);
47-
if (b & 1) apply(--b, f);
48-
}
49-
int zl = __builtin_ctz(l), zr = __builtin_ctz(r);
50-
for (int i = min(zl, zr)+1; i <= log; i++) {
51-
if (i > zl) pull(l >> i);
52-
if (i > zr) pull((r - 1) >> i);
53-
}
54-
}
4+
int N, log, S;
5+
vector<T> d;
6+
vector<F> lz;
7+
lazy_segtree(const vector<T>& v):
8+
N(sz(v)), log(__lg(2 * N - 1)), S(1 << log), d(2 * S, e()),
9+
lz(S, id()) {
10+
for (int i = 0; i < N; i++) d[S + i] = v[i];
11+
for (int i = S - 1; i >= 1; i--) pull(i);
12+
}
13+
void apply(int k, F f) {
14+
d[k] = onto(f, d[k]);
15+
if (k < S) lz[k] = comp(f, lz[k]);
16+
}
17+
void push(int k) {
18+
apply(2 * k, lz[k]), apply(2 * k + 1, lz[k]), lz[k] = id();
19+
}
20+
void push(int l, int r) {
21+
int zl = __builtin_ctz(l), zr = __builtin_ctz(r);
22+
for (int i = log; i > min(zl, zr); i--) {
23+
if (i > zl) push(l >> i);
24+
if (i > zr) push((r - 1) >> i);
25+
}
26+
}
27+
void pull(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
28+
void set(int p, T x) {
29+
p += S;
30+
for (int i = log; i >= 1; i--) push(p >> i);
31+
for (d[p] = x; p /= 2;) pull(p);
32+
}
33+
T query(int l, int r) {
34+
if (l == r) return T{};
35+
push(l += S, r += S);
36+
T vl = e(), vr = e();
37+
for (; l < r; l /= 2, r /= 2) {
38+
if (l & 1) vl = op(vl, d[l++]);
39+
if (r & 1) vr = op(d[--r], vr);
40+
}
41+
return op(vl, vr);
42+
}
43+
void update(int l, int r, F f) {
44+
if (l == r) return;
45+
push(l += S, r += S);
46+
for (int a = l, b = r; a < b; a /= 2, b /= 2) {
47+
if (a & 1) apply(a++, f);
48+
if (b & 1) apply(--b, f);
49+
}
50+
int zl = __builtin_ctz(l), zr = __builtin_ctz(r);
51+
for (int i = min(zl, zr) + 1; i <= log; i++) {
52+
if (i > zl) pull(l >> i);
53+
if (i > zr) pull((r - 1) >> i);
54+
}
55+
}
5556
};

content/data-structures/LineContainer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ struct LineContainer: multiset<Line, less<>> {
2323
bool isect(iterator x, iterator y) {
2424
if (y == end()) return x->p = inf, 0;
2525
if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
26-
else
27-
x->p = div(y->m - x->m, x->k - y->k);
26+
else x->p = div(y->m - x->m, x->k - y->k);
2827
return x->p >= y->p;
2928
}
3029
void add(ll k, ll m) {

0 commit comments

Comments
 (0)