forked from brianbbsu/8BQube
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12a34a4
commit 2468bcb
Showing
82 changed files
with
316 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "common.h" | ||
struct hopcroftKarp { // 0-based | ||
bool dfs(int a, int L, vector<vector<int>> &g, | ||
vector<int> &btoa, vector<int> &A, | ||
vector<int> &B) { | ||
if (A[a] != L) return 0; | ||
A[a] = -1; | ||
for (int b : g[a]) | ||
if (B[b] == L + 1) { | ||
B[b] = 0; | ||
if (btoa[b] == -1 || | ||
dfs(btoa[b], L + 1, g, btoa, A, B)) | ||
return btoa[b] = a, 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int solve(vector<vector<int>> &g, int m) { | ||
int res = 0; | ||
vector<int> btoa(-1, m), A(g.size()), | ||
B(btoa.size()), cur, next; | ||
for (;;) { | ||
fill(all(A), 0), fill(all(B), 0); | ||
cur.clear(); | ||
for (int a : btoa) | ||
if (a != -1) A[a] = -1; | ||
for (int a = 0; a < g.size(); a++) | ||
if (A[a] == 0) cur.push_back(a); | ||
/// Find all layers using bfs. | ||
for (int lay = 1;; lay++) { | ||
bool islast = 0; | ||
next.clear(); | ||
for (int a : cur) | ||
for (int b : g[a]) { | ||
if (btoa[b] == -1) { | ||
B[b] = lay; | ||
islast = 1; | ||
} else if (btoa[b] != a && !B[b]) { | ||
B[b] = lay; | ||
next.push_back(btoa[b]); | ||
} | ||
} | ||
if (islast) break; | ||
if (next.empty()) return res; | ||
for (int a : next) A[a] = lay; | ||
cur.swap(next); | ||
} | ||
/// Use DFS to scan for augmenting paths. | ||
for (int a = 0; a < g.size(); a++) | ||
res += dfs(a, 0, g, btoa, A, B); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
struct fraction { | ||
ll n, d; | ||
fraction(const ll &_n=0, const ll &_d=1): n(_n), d(_d) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
map<ll, int> cnt; | ||
void PollardRho(ll n) { | ||
if (n == 1) return; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
namespace schreier { | ||
int n; | ||
vector<vector<vector<int>>> bkts, binv; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
#define MAXN 11 | ||
int factorial[MAXN]; | ||
inline void init(){ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
#include "ExtGCD.cpp" | ||
ll solve(ll x1, ll m1, ll x2, ll m2) { | ||
ll g = gcd(m1, m2); | ||
if ((x2 - x1) % g) return -1; // no sol | ||
m1 /= g; m2 /= g; | ||
pll p = exgcd(m1, m2); | ||
ll x, y; | ||
extgcd(m1, m2, __gcd(m1, m2), x, y); | ||
ll lcm = m1 * m2 * g; | ||
ll res = p.first * (x2 - x1) * m1 + x1; | ||
ll res = x * (x2 - x1) * m1 + x1; | ||
// be careful with overflow | ||
return (res % lcm + lcm) % lcm; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
// O(p^k + log^2 n), pk = p^k | ||
ll prod[MAXP]; | ||
ll fac_no_p(ll n, ll p, ll pk) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
template<int MAXN> | ||
struct FFT { | ||
using val_t = complex<double>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
//9223372036737335297, 3 | ||
#define base ll // complex<double> | ||
#define N 524288 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
//(2^16)+1, 65537, 3 | ||
//7*17*(2^23)+1, 998244353, 3 | ||
//1255*(2^20)+1, 1315962881, 3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
struct Poly { | ||
mint base; // f(x) = poly[x - base] | ||
vector<mint> poly; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#include "common.h" | ||
const int N = 1021; | ||
struct CircleCover { | ||
int C; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
#include "Default_code.cpp" | ||
void hull(vector<pll> &dots) { // n=1 => ans = {} | ||
sort(dots.begin(), dots.end()); | ||
vector<pll> ans(1, dots[0]); | ||
for (int ct = 0; ct < 2; ++ct, reverse(ALL(dots))) | ||
for (int i = 1, t = SZ(ans); i < SZ(dots); ans.pb(dots[i++])) | ||
while (SZ(ans) > t && ori(ans[SZ(ans) - 2], ans.back(), dots[i]) <= 0) | ||
for (int ct = 0; ct < 2; ++ct, reverse(all(dots))) | ||
for (int i = 1, t = ans.size(); i < dots.size(); ans.emplace_back(dots[i++])) | ||
while (ans.size() > t && ori(ans.end()[-2], ans.back(), dots[i]) <= 0) | ||
ans.pop_back(); | ||
ans.pop_back(), ans.swap(dots); | ||
} |
Oops, something went wrong.