Skip to content

Commit

Permalink
refactor: upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiphereth-A committed Feb 6, 2025
1 parent 60e7c32 commit d411d1a
Show file tree
Hide file tree
Showing 549 changed files with 4,190 additions and 2,625 deletions.
1 change: 1 addition & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
- name: Clean up
if: ${{ matrix.type == 'huge' }}
run: |
rm -rf fonts img src/cheatsheet src/data src/doc_tex src/meta_test src/meta_test_huge src/src src/test_tinplate
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
sudo docker builder prune -a
Expand Down
23 changes: 13 additions & 10 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ notebook:
- max_area_t: 凸包内面积最大的三角形
code_ext: hpp
test_ext: cpp
- coverage_rect_min_area: 最小面积覆盖矩形
code_ext: hpp
test_ext: cpp
- coverage_rect_min_circum: 最小周长覆盖矩形
- coverage_rect: 覆盖矩形(最小面积,最小周长)
code_ext: hpp
test_ext: cpp
- max_dis_cvh: 两凸包中的点的最远距离
Expand Down Expand Up @@ -647,6 +644,18 @@ notebook:
code_ext: hpp
test_ext: cpp
comb:
- gen_fact: 阶乘模序列
code_ext: hpp
test_ext: cpp
- gen_ifact: 阶乘逆模序列
code_ext: hpp
test_ext: cpp
- fact_helper: 阶乘与阶乘逆辅助类
code_ext: hpp
test_ext: cpp
- factl_helper: 大数阶乘与阶乘逆辅助类
code_ext: hpp
test_ext: cpp
- binom: 二项式系数
code_ext: hpp
test_ext: cpp
Expand Down Expand Up @@ -677,12 +686,6 @@ notebook:
- gen_partition: 划分数序列
code_ext: hpp
test_ext: cpp
- gen_fact: 阶乘模序列
code_ext: hpp
test_ext: cpp
- gen_ifact: 阶乘逆模序列
code_ext: hpp
test_ext: cpp
- gen_inv: 逆元序列
code_ext: hpp
test_ext: cpp
Expand Down
2 changes: 1 addition & 1 deletion src/code/bit/bswap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace tifa_libs::bit {

// From GCC lib
template <class T>
CEXP T bswap(T x) {
CEXP T bswap(T x) NE {
if CEXP (sizeof(T) == 2) return __builtin_bswap16(x);
if CEXP (sizeof(T) == 4) return __builtin_bswap32(x);
if CEXP (sizeof(T) == 8) return __builtin_bswap64(x);
Expand Down
2 changes: 1 addition & 1 deletion src/code/bit/cntlsb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::bit {

template <class T>
CEXP int cntlsb(T x) {
CEXP int cntlsb(T x) NE {
CEXP int nd = sizeof(T) * 8;
static_assert(nd <= 64);
if CEXP (nd <= sizeof(unsigned) * 8) return __builtin_clrsb(x);
Expand Down
2 changes: 1 addition & 1 deletion src/code/bit/ffs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::bit {

template <class T>
CEXP int ffs(T x) {
CEXP int ffs(T x) NE {
CEXP int nd = sizeof(T) * 8;
static_assert(nd <= 128);
CEXP int nd_ull = sizeof(long long) * 8;
Expand Down
2 changes: 1 addition & 1 deletion src/code/bit/lowbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::bit {

template <class T>
CEXP T lowbit(T x) { return T(1) << std::countr_zero(x); }
CEXP T lowbit(T x) NE { return T(1) << std::countr_zero(x); }

} // namespace tifa_libs::bit

Expand Down
2 changes: 1 addition & 1 deletion src/code/bit/parity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::bit {

template <class T>
CEXP int parity(T x) {
CEXP int parity(T x) NE {
CEXP int nd = sizeof(T) * 8;
static_assert(nd <= 128);
CEXP int nd_ull = sizeof(unsigned long long) * 8;
Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_dda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_dda(u32 ball, u32 box) { return qpow<mint>(box, ball); }
CEXP mint ball_box_dda(u32 ball, u32 box) NE { return qpow<mint>(box, ball); }

} // namespace tifa_libs::math

Expand Down
10 changes: 7 additions & 3 deletions src/code/comb/ball_box_ddl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_ddl(u32, u32 box, spnuu pows, Binom<mint> CR binom) {
CEXP mint ball_box_ddl(u32, u32 box, spnuu pows, binom<mint> CR b) NE {
mint ans = 0;
bool f = box & 1;
flt_ (u32, i, 1, box + 1) f ? (ans += binom.mCn(box, i) * pows[i]) : (ans -= binom.mCn(box, i) * pows[i]), f ^= 1;
flt_ (u32, i, 1, box + 1) {
auto _ = b.mCn(box, i) * pows[i];
f ? ans += _ : ans -= _;
f ^= 1;
}
return ans;
}
template <class mint>
CEXP mint ball_box_ddl(u32 ball, u32 box, Binom<mint> CR binom) { return ball_box_ddl<mint>(ball, box, gen_pows(box + 1, ball, mint::mod()), binom); }
CEXP mint ball_box_ddl(u32 ball, u32 box, binom<mint> CR b) NE { return ball_box_ddl<mint>(ball, box, gen_pows(box + 1, ball, mint::mod()), b); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_ddm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_ddm(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mPn(box, ball); }
CEXP mint ball_box_ddm(u32 ball, u32 box, binom<mint> CR b) NE { return b.mPn(box, ball); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_dia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
CEXP auto ball_box_dia(u32 ball, u32 box, poly CR s2r) { return std::reduce(s2r.begin(), s2r.begin() + (min(ball, box) + 1), TPN poly::val_t{}); }
CEXP auto ball_box_dia(u32 ball, u32 box, poly CR s2r) NE { return std::reduce(s2r.begin(), s2r.begin() + (min(ball, box) + 1), TPN poly::val_t{}); }
template <class poly>
CEXP auto ball_box_dia(u32 ball, u32 box) { return ball_box_dia<poly>(ball, box, gen_stirling2_row<poly>(ball)); }
CEXP auto ball_box_dia(u32 ball, u32 box) NE { return ball_box_dia<poly>(ball, box, gen_stirling2_row<poly>(ball)); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_dil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
CEXP auto ball_box_dil(u32 ball, u32 box, poly CR s2r) { return box > ball ? 0 : s2r[box]; }
CEXP auto ball_box_dil(u32 ball, u32 box, poly CR s2r) NE { return box > ball ? 0 : s2r[box]; }
template <class poly>
CEXP auto ball_box_dil(u32 ball, u32 box) { return ball_box_dil<poly>(ball, box, gen_stirling2_row<poly>(ball)); }
CEXP auto ball_box_dil(u32 ball, u32 box) NE { return ball_box_dil<poly>(ball, box, gen_stirling2_row<poly>(ball)); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_dim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_dim(u32 ball, u32 box) { return box >= ball; }
CEXP mint ball_box_dim(u32 ball, u32 box) NE { return box >= ball; }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_ida.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_ida(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mCn(box + ball - 1, box - 1); }
CEXP mint ball_box_ida(u32 ball, u32 box, binom<mint> CR b) NE { return b.mCn(box + ball - 1, box - 1); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_idl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_idl(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mCn(ball - 1, box - 1); }
CEXP mint ball_box_idl(u32 ball, u32 box, binom<mint> CR b) NE { return b.mCn(ball - 1, box - 1); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_idm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_idm(u32 ball, u32 box, Binom<mint> CR binom) { return binom.mCn(box, ball); }
CEXP mint ball_box_idm(u32 ball, u32 box, binom<mint> CR b) NE { return b.mCn(box, ball); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_iia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
CEXP auto ball_box_iia(u32 ball, u32, poly CR bbiif) { return bbiif[ball]; }
CEXP auto ball_box_iia(u32 ball, u32, poly CR bbiif) NE { return bbiif[ball]; }
template <class poly>
CEXP auto ball_box_iia(u32 ball, u32 box) { return ball_box_iia<poly>(ball, box, gen_ball_box_ii<poly>(box, ball)); }
CEXP auto ball_box_iia(u32 ball, u32 box) NE { return ball_box_iia<poly>(ball, box, gen_ball_box_ii<poly>(box, ball)); }

} // namespace tifa_libs::math

Expand Down
4 changes: 2 additions & 2 deletions src/code/comb/ball_box_iil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace tifa_libs::math {

template <class poly>
CEXP auto ball_box_iil(u32 ball, u32 box, poly CR bbiif) { return ball >= box ? bbiif[ball - box] : TPN poly::val_t{0}; }
CEXP auto ball_box_iil(u32 ball, u32 box, poly CR bbiif) NE { return ball >= box ? bbiif[ball - box] : TPN poly::val_t{0}; }
template <class poly>
CEXP auto ball_box_iil(u32 ball, u32 box) { return ball_box_iil<poly>(ball, box, gen_ball_box_ii<poly>(box, ball)); }
CEXP auto ball_box_iil(u32 ball, u32 box) NE { return ball_box_iil<poly>(ball, box, gen_ball_box_ii<poly>(box, ball)); }

} // namespace tifa_libs::math

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/ball_box_iim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::math {

template <class mint>
CEXP mint ball_box_iim(u32 ball, u32 box) { return box >= ball; }
CEXP mint ball_box_iim(u32 ball, u32 box) NE { return box >= ball; }

} // namespace tifa_libs::math

Expand Down
29 changes: 14 additions & 15 deletions src/code/comb/binom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@
#define TIFALIBS_COMB_BINOM

#include "../util/traits.hpp"
#include "gen_fact.hpp"
#include "gen_ifact.hpp"
#include "fact_helper.hpp"

namespace tifa_libs::math {

template <class mint>
struct Binom {
vec<mint> fact, ifact;
template <class mint, class fact = fact_helper<mint>>
requires std::same_as<mint, TPN fact::val_t>
struct binom {
using fact_t = fact;

static CEXP u64 mod() { return mint::mod(); }
CEXPE Binom(u32 max_m = 0) : fact(gen_fact<mint>(std::min((u32)mod(), max_m + 1))), ifact(gen_ifact<mint>(std::min((u32)mod(), max_m + 1))) {}
CEXPE binom(u32 max_m = fact::DEFUALT_MAX) NE { fact::ensure(max_m + 1); }

// $\binom{m}{n}$
CEXP mint mCn(uint_c auto m, uint_c auto n) const { return m < n ? 0 : mPn(m, n) * ifact[(usz)n]; }
CEXP mint mCn(uint_c auto m, uint_c auto n) CNE { return m < n ? 0 : mPn(m, n) * fact::get_ifact(n); }
// $\binom{m}{n}$
template <sint_c T>
CEXP mint mCn(T m, T n) const { return m < n || n < 0 ? 0 : mCn(to_uint_t<T>(m), to_uint_t<T>(n)); }
CEXP mint mCn(T m, T n) CNE { return m < n || n < 0 ? 0 : mCn(to_uint_t<T>(m), to_uint_t<T>(n)); }
//! mint::mod() must be prime
template <int_c T>
CEXP mint lucas(T m, T n) const {
CEXP mint lucas(T m, T n) CNE {
assert(mint::mod() > 1);
auto f = [this](auto &&f, auto m, auto n) -> mint { return n == 0 ? 1 : this->mCn(m % mod(), n % mod()) * f(f, m / mod(), n / mod()); };
auto f = [this](auto &&f, auto m, auto n) NE -> mint { return n == 0 ? 1 : this->mCn(m % fact::mod(), n % fact::mod()) * f(f, m / fact::mod(), n / fact::mod()); };
return m < n || n < 0 ? 0 : f(f, to_uint_t<T>(m), to_uint_t<T>(n));
}
// $\binom{m}{n} \cdot n!$
CEXP mint mPn(uint_c auto m, uint_c auto n) const { return m < n ? 0 : fact[(usz)m] * ifact[(usz)(m - n)]; }
CEXP mint mPn(uint_c auto m, uint_c auto n) CNE { return m < n ? 0 : fact::get_fact(m) * fact::get_ifact(m - n); }
// $\binom{m}{n} \cdot n!$
template <sint_c T>
CEXP mint mPn(T m, T n) const { return m < n || n < 0 ? 0 : mPn(to_uint_t<T>(m), to_uint_t<T>(n)); }
CEXP mint mPn(T m, T n) CNE { return m < n || n < 0 ? 0 : mPn(to_uint_t<T>(m), to_uint_t<T>(n)); }
// $[x^n] \frac{1}{(1-x)^m}$
CEXP mint mHn(uint_c auto m, uint_c auto n) const { return n <= 0 ? n == 0 : mCn(m + n - 1, n); }
CEXP mint mHn(uint_c auto m, uint_c auto n) CNE { return n <= 0 ? n == 0 : mCn(m + n - 1, n); }
// $[x^n] \frac{1}{(1-x)^m}$
template <sint_c T>
CEXP mint mHn(T m, T n) const { return m < 0 || n <= 0 ? n == 0 : mHn(to_uint_t<T>(m), to_uint_t<T>(n)); }
CEXP mint mHn(T m, T n) CNE { return m < 0 || n <= 0 ? n == 0 : mHn(to_uint_t<T>(m), to_uint_t<T>(n)); }
};

} // namespace tifa_libs::math
Expand Down
10 changes: 5 additions & 5 deletions src/code/comb/exlucas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
namespace tifa_libs::math {

// Calculate $\binom{m}{n} \bmod p$, p can be ANY INTEGER
class ExLucas {
class exlucas {
struct TIFA {
const u32 p, q;
const bool no_proot;
u64 m_;
vecuu facp, ifacp;
CEXP TIFA(u32 p, u32 q) : p(p), q(q), no_proot(p == 2 && q >= 3) {
CEXP TIFA(u32 p, u32 q) NE : p(p), q(q), no_proot(p == 2 && q >= 3) {
assert(p <= 100'000'000 && q > 0), m_ = 1;
while (q--) (m_ *= p), assert(m_ <= 100'000'000);
facp.resize(m_), facp[0] = facp[1] = 1;
Expand All @@ -24,7 +24,7 @@ class ExLucas {
else facp[i] = facp[i - 1] * i % m_;
ifacp = gen_invseq(facp, m_);
}
CEXP u64 operator()(i64 m, i64 n) const {
CEXP u64 operator()(i64 m, i64 n) CNE {
if (m < n || n < 0) return 0;
i64 r = m - n;
i32 e0 = 0, eq = 0;
Expand All @@ -43,7 +43,7 @@ class ExLucas {
vec<TIFA> cs;

public:
CEXPE ExLucas(u32 md) : m_(md) {
CEXPE exlucas(u32 md) NE : m_(md) {
assert(md < 100'000'000);
flt_ (u32, i, 2, isqrt(md) + 1)
if (md % i == 0) {
Expand All @@ -54,7 +54,7 @@ class ExLucas {
if (md > 1) ms.push_back(md), cs.emplace_back(md, 1);
}

CEXP u64 operator()(i64 m, i64 n) const {
CEXP u64 operator()(i64 m, i64 n) CNE {
if (m_ == 1 || m < n || n < 0) return 0;
vecii b;
for (b.reserve(cs.size()); auto CR i : cs) b.push_back((i64)i(m, n));
Expand Down
52 changes: 52 additions & 0 deletions src/code/comb/fact_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef TIFALIBS_COMB_FACT_HELPER
#define TIFALIBS_COMB_FACT_HELPER

#include "../util/traits.hpp"

namespace tifa_libs::math {

template <mint_c mint>
struct fact_helper {
using val_t = mint;
static CEXP u32 DEFUALT_MAX = 10'000'001;
static CEXP u64 mod() NE { return val_t::mod(); }
static inline vec<val_t> fact, ifact;

fact_helper() = delete;

// ensure fact.size() >= sz
static CEXP void ensure(u32 sz = DEFUALT_MAX) NE {
if (sz = std::max(2_u32, std::min((u32)mod(), sz)); sz <= fact.size()) return;
u32 pre = (u32)fact.size();
fact.resize(sz), ifact.resize(sz);
if (pre < 2) pre = 2, fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
flt_ (u32, i, pre, sz) fact[i] = fact[i - 1] * i;
ifact.back() = fact.back().inv();
for (u32 i = sz - 1; i > pre; --i) ifact[i - 1] = ifact[i] * i;
}

static CEXP val_t get_fact(u64 n) NE {
if (n >= mod()) [[unlikely]]
return 0;
if (fact.empty()) [[unlikely]]
ensure();
if (n < fact.size()) [[likely]]
return fact[n];
val_t _ = fact.back() * n;
flt_ (u64, i, fact.size(), n) _ *= i;
return _;
}
static CEXP val_t get_ifact(u64 n) NE {
if (n >= mod()) [[unlikely]]
return 0;
if (fact.empty()) [[unlikely]]
ensure();
if (n < ifact.size()) [[likely]]
return ifact[n];
return get_fact(n).inv();
}
};

} // namespace tifa_libs::math

#endif
Loading

0 comments on commit d411d1a

Please sign in to comment.