전체 글
-
intToPerm, permToInt232's competitive-programming templates./misc 2024. 12. 8. 00:15
constexpr int P = 7;const auto fac = [] { std::array f {}; f[0] = 1; for (int i = 1; i intToPerm(int k) { assert(0 res; for (int i = P - 1; i >= 0; --i) { int w = k / fac[P - 1 - i] % (P - i); res[i] = w; for (int j = i + 1; j = w) { res[j] += 1; } } } return res;}int permToInt(const std::array& a) { int res = 0; for (int i = 0; i a[j]) { small += 1; ..
-
getBcc232's competitive-programming templates./graphs 2024. 11. 19. 22:59
std::vector>> getBccV(const std::vector>& g) { int n = int(g.size()); std::vector dep(n, -1); std::vector low(n); std::vector> stk; std::vector>> bcc; auto dfs = [&](auto&& dfs, int u, int p) -> void { for (int v : g[u]) { assert(0 dep[v]) { stk.emplace_back(u, v); } if (dep[v] != -1) { low[u] = std::min(low[u], dep[v]); } else { low[v] = dep[v]..
-
AhoCorasick232's competitive-programming templates./strings 2024. 11. 4. 19:25
template struct AhoCorasick { static_assert(L to; std::optional> ids; int operator[](int idx) const { return to[idx]; } int& operator[](int idx) { return to[idx]; } Node() : fail(0), near(0), chain_sz(0), to({}) { void(0); } }; int n; std::vector lens; std::vector nodes; template AhoCorasick(const std::vector& s) : n(int(s.size())), lens(n), nodes(1) ..
-
treeBinaryTransform232's competitive-programming templates./trees 2024. 11. 2. 16:26
template std::vector>> treeBinaryTransform(std::vector>> g, int root = 0, bool bidirectional = true) { int n = int(g.size()); assert(0 >> res_g(2 * n); auto dfs = [&](auto&& dfs, int from, int to, int idx) -> void { for (int i = idx; i
-
Geometry232's competitive-programming templates./geometry 2024. 10. 27. 13:04
namespace Geometry { using F = long double; template struct PointBase { constexpr static T eps = T(1E-9); T x; T y; PointBase() : x(0), y(0) { void(0); } PointBase(T x, T y) : x(x), y(y) { void(0); } template operator PointBase() const { return {U(x), U(y)}; } friend PointBase operator-(const PointBase& a, const PointBase& b) { return {a...
-
LiChaoTree232's competitive-programming templates./data structures 2024. 10. 24. 22:24
struct LiChaoTree { constexpr static long long inf = std::numeric_limits::max(); struct Line { long long k; long long m; [[nodiscard]] long long get(long long x) const { return k * x + m; } Line(long long k, long long m) : k(k), m(m) { void(0); } }; struct Node { int lft; int rgt; Line line; Node() : lft(0), rgt(0), line(0, -inf) { void(0); } ..
-
Cht232's competitive-programming templates./data structures 2024. 10. 24. 20:20
struct Cht { std::vector> lines; std::vector x; [[nodiscard]] long long get(long long y) const { int i = std::lower_bound(x.begin(), x.end(), y) - x.begin(); assert(i = m) { return; } if (!x.empty()) { x.pop_back(); } m = lines.back().second; lines.pop_back(); } while (!x.empty() && x.back() >= (lines.back().second - m) / (k - lines.back().fi..
-
(useless) furthestPoints (rotating calipers)232's competitive-programming templates./geometry 2024. 10. 23. 16:26
upd : now all in Geometry..std::pair furthestPoints(const std::vector& pts) { assert(!pts.empty()); auto hull = getConvexHull(pts); int n = hull.size(); G max_dist = -1; std::pair res; for (int i = 0, j = 0; i = 0) { j = (j + 1) % n; if (auto d = dist2(hull[i], hull[j]); max_dist