Skip to content

Commit

Permalink
refactor: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiphereth-A committed May 15, 2024
1 parent 7c79a3f commit cbd71da
Show file tree
Hide file tree
Showing 627 changed files with 1,285 additions and 9,371 deletions.
1 change: 0 additions & 1 deletion ICPCnotebook.cls
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

% User defined command
\newcommand{\lcm}{\operatorname{lcm}}
\newcommand{\subjectto}{~s.t.~}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}

Expand Down
50 changes: 28 additions & 22 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ notebook:
- max_area_t: 凸包内面积最大的三角形
code_ext: hpp
test_ext: cpp
- coverage_rect_with_min_area: 最小面积覆盖矩形
- coverage_rect_min_area: 最小面积覆盖矩形
code_ext: hpp
test_ext: cpp
- coverage_rect_with_min_circum: 最小周长覆盖矩形
- coverage_rect_min_circum: 最小周长覆盖矩形
code_ext: hpp
test_ext: cpp
- max_dis_cvh: 两凸包中的点的最远距离
Expand All @@ -282,16 +282,16 @@ notebook:
- extan_cc: 两圆的外切线
code_ext: hpp
test_ext: cpp
- inv_c2c: 未经过反演中心的圆的几何反演
- inv_p2p: 点的反演
code_ext: hpp
test_ext: cpp
- inv_c2l: 经过反演中心的圆的几何反演
- inv_l2c: 直线的反演
code_ext: hpp
test_ext: cpp
- inv_l2c: 直线的几何反演
- inv_c2c: 圆的反演(未经过反演中心)
code_ext: hpp
test_ext: cpp
- inv_p2p: 点的几何反演
- inv_c2l: 圆的反演(经过反演中心)
code_ext: hpp
test_ext: cpp
- dist_pl: 点与直线距离
Expand All @@ -306,7 +306,13 @@ notebook:
- ins_ll: 直线交点
code_ext: hpp
test_ext: cpp
- is_ins_ss: 判断线段是否相交
- is_ins_sl: 判断线段与直线是否相交
code_ext: hpp
test_ext: cpp
- is_ins_ss: 判断两线段是否相交
code_ext: hpp
test_ext: cpp
- any_ins_ss: 判断多条线段是否相交
code_ext: hpp
test_ext: cpp
- is_on_s: 判断点是否在直线上
Expand All @@ -318,19 +324,22 @@ notebook:
- proj: 点在直线上的投影与对称点
code_ext: hpp
test_ext: cpp
- make_c_ppp: 根据三点构造圆
- make_c_ppp: 构造圆(经过的三点)
code_ext: hpp
test_ext: cpp
- make_c_rcc_ex: 根据半径和两外切圆构造圆
- make_c_rpp: 构造圆(半径和经过的两点)
code_ext: hpp
test_ext: cpp
- make_c_rll: 根据半径和两切线构造圆
- make_c_rpl: 构造圆(半径,切线和经过的一点)
code_ext: hpp
test_ext: cpp
- make_c_rpl: 根据半径,切线和经过的一点构造圆
- make_c_rll: 构造圆(半径和两切线)
code_ext: hpp
test_ext: cpp
- make_c_rpp: 根据半径和经过的两点构造圆
- make_c_rcc_ex: 构造圆(半径和两外切圆)
code_ext: hpp
test_ext: cpp
- make_c_pcc_ex: 构造圆(经过的一点和两外切圆)
code_ext: hpp
test_ext: cpp
- min_cover_c: 最小覆盖圆
Expand Down Expand Up @@ -414,6 +423,12 @@ notebook:
- tcenter_x: 三角形 Fermat 点
code_ext: hpp
test_ext: cpp
- aunion_cs: 圆的面积并
code_ext: hpp
test_ext: cpp
- aunion_pos: 多边形的面积并
code_ext: hpp
test_ext: cpp
geo3d:
- point3d: 三维点
code_ext: hpp
Expand Down Expand Up @@ -841,28 +856,19 @@ notebook:
- mint_2e61n1: 模整数类(固定,61-1)
code_ext: hpp
test_ext: cpp
- mint_ss: 模整数类(静态,简单实现)
code_ext: hpp
test_ext: cpp
- mint_s30: 模整数类(静态,30)
code_ext: hpp
test_ext: cpp
- mint_s63: 模整数类(静态,63)
code_ext: hpp
test_ext: cpp
- mint_ds: 模整数类(动态,简单实现)
code_ext: hpp
test_ext: cpp
- mint_d31: 模整数类(动态,31)
code_ext: hpp
test_ext: cpp
- mint_d63: 模整数类(动态,63)
code_ext: hpp
test_ext: cpp
- mul_mod_s: 有符号模乘法
code_ext: hpp
test_ext: cpp
- mul_mod_u: 无符号模乘法
- mul_mod: 模乘法
code_ext: hpp
test_ext: cpp
- qpow_mod: 模快速幂
Expand Down
20 changes: 10 additions & 10 deletions src/cheatsheet/nt-const.tex
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ \subsection{本质不同质因子数, 因子数, 素数个数}

\begin{tabular}{llll|llll}
\hline
\(n\) & \(\max\{\omega(n)\}\) & \(\max\{d(n)\}\) & \(\pi(n)\) & \(n\) & \(\max\{\omega(n)\}\) & \(\max\{d(n)\}\) & \(\pi(n)\) \\
\(n\) & \(\max\{\omega(n)\}\) & \(\max\{d(n)\}\) & \(\pi(n)\) & \(n\) & \(\max\{\omega(n)\}\) & \(\max\{d(n)\}\) & \(\pi(n)\) \\
\hline
\(10^1\) & \(2\) & \(4\) & \(4\) & \(10^{10}\) & \(10\) & \(2304\) & \(455052511\) \\
\(10^2\) & \(3\) & \(12\) & \(25\) & \(10^{11}\) & \(10\) & \(4032\) & \(4118054813\) \\
\(10^3\) & \(4\) & \(32\) & \(168\) & \(10^{12}\) & \(11\) & \(6720\) & \\
\(10^4\) & \(5\) & \(64\) & \(1229\) & \(10^{13}\) & \(12\) & \(10752\) & \\
\(10^5\) & \(6\) & \(128\) & \(9592\) & \(10^{14}\) & \(12\) & \(17280\) & \\
\(10^6\) & \(7\) & \(240\) & \(78498\) & \(10^{15}\) & \(13\) & \(26880\) & \\
\(10^7\) & \(8\) & \(448\) & \(664579\) & \(10^{16}\) & \(13\) & \(41472\) & \\
\(10^8\) & \(8\) & \(768\) & \(5761455\) & \(10^{17}\) & \(14\) & \(64512\) & \\
\(10^9\) & \(9\) & \(1344\) & \(50847534\) & \(10^{18}\) & \(15\) & \(103680\) & \\
\(10^1\) & \(2\) & \(4\) & \(4\) & \(10^{10}\) & \(10\) & \(2~304\) & \(455~052~511\) \\
\(10^2\) & \(3\) & \(12\) & \(25\) & \(10^{11}\) & \(10\) & \(4~032\) & \(4~118~054~813\) \\
\(10^3\) & \(4\) & \(32\) & \(168\) & \(10^{12}\) & \(11\) & \(6~720\) & \\
\(10^4\) & \(5\) & \(64\) & \(1~229\) & \(10^{13}\) & \(12\) & \(10~752\) & \\
\(10^5\) & \(6\) & \(128\) & \(9~592\) & \(10^{14}\) & \(12\) & \(17~280\) & \\
\(10^6\) & \(7\) & \(240\) & \(78~498\) & \(10^{15}\) & \(13\) & \(26~880\) & \\
\(10^7\) & \(8\) & \(448\) & \(664~579\) & \(10^{16}\) & \(13\) & \(41~472\) & \\
\(10^8\) & \(8\) & \(768\) & \(5~761~455\) & \(10^{17}\) & \(14\) & \(64~512\) & \\
\(10^9\) & \(9\) & \(1~344\) & \(50~847~534\) & \(10^{18}\) & \(15\) & \(103~680\) & \\
\hline
\end{tabular}
12 changes: 6 additions & 6 deletions src/code/comb/binom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ struct Binom {

static CEXP u64 mod() { return mint::mod(); }

// \binom{m}{n}
// $\binom{m}{n}$
template <uint_c T>
CEXP mint mCn(T m, T n) const { return m < n ? 0 : mPn(m, n) * ifact[(usz)n]; }
// \binom{m}{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)); }

// \binom{m}{n} * n!
// $\binom{m}{n} \cdot n!$
template <uint_c T>
CEXP mint mPn(T m, T n) const { return m < n ? 0 : fact[(usz)m] * ifact[(usz)(m - n)]; }
// \binom{m}{n} * 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)); }

// [x^n] 1 / (1-x)^m
// $[x^n] \frac{1}{(1-x)^m}$
template <uint_c T>
CEXP mint mHn(T m, T n) const { return n <= 0 ? n == 0 : mCn(m + n - 1, n); }
// [x^n] 1 / (1-x)^m
// $[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)); }
};
Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/gen_derange.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_COMB_GEN_DERANGE
#define TIFALIBS_COMB_GEN_DERANGE

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"

namespace tifa_libs::math {

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/gen_fact.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_COMB_GEN_FACT
#define TIFALIBS_COMB_GEN_FACT

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"

namespace tifa_libs::math {

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/gen_ifact.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_COMB_GEN_IFACT
#define TIFALIBS_COMB_GEN_IFACT

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"
#include "gen_inv.hpp"

namespace tifa_libs::math {
Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/gen_inv.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_COMB_GEN_INV
#define TIFALIBS_COMB_GEN_INV

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"

namespace tifa_libs::math {

Expand Down
2 changes: 1 addition & 1 deletion src/code/comb/gen_invseq.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_COMB_GEN_INVSEQ
#define TIFALIBS_COMB_GEN_INVSEQ

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"
#include "../nt/inverse.hpp"

namespace tifa_libs::math {
Expand Down
6 changes: 3 additions & 3 deletions src/code/conv/conv_3ntt.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_CONV_CONV_3NTT
#define TIFALIBS_CONV_CONV_3NTT

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"
#include "conv_dft.hpp"
#include "ntt.hpp"

Expand All @@ -10,8 +10,8 @@ namespace tifa_libs::math {
// 167772161, 469762049, 754974721
template <class mint0, class mint1, class mint2>
CEXP vecu64 conv_3ntt_u64(std::tuple<NTT<mint0>, NTT<mint1>, NTT<mint2>> &ntt3, vecu64 CR l, vecu64 CR r, u64 mod, u32 ans_size = 0) {
CEXP u32 m0 = mint0::mod(), m1 = mint1::mod(), m2 = mint2::mod();
const u32 r01 = mint1(m0).inv().val(), r02 = mint2(m0).inv().val(), r12 = mint2(m1).inv().val(), r02r12 = (u32)mul_mod_u(r02, r12, m2);
CEXP u64 m0 = mint0::mod(), m1 = mint1::mod(), m2 = mint2::mod();
const u64 r01 = mint1(m0).inv().val(), r02 = mint2(m0).inv().val(), r12 = mint2(m1).inv().val(), r02r12 = (u32)mul_mod_u(r02, r12, m2);
const u64 w1 = m0 % mod, w2 = mul_mod_u(m0, m1, mod);

if (!ans_size) ans_size = u32(l.size() + r.size() - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/code/ds/skew_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tifa_libs::ds {

template <class T, class C = std::less<T>>
class SkewHeap {
class skew_heap {
static CEXP C comp_{};
struct TIFA {
T k, lz;
Expand Down
2 changes: 1 addition & 1 deletion src/code/fast/str2uint_mod.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TIFALIBS_FAST_STR2UINT_MOD
#define TIFALIBS_FAST_STR2UINT_MOD

#include "../math/mul_mod_u.hpp"
#include "../math/mul_mod.hpp"
#include "str2uint_si64.hpp"

namespace tifa_libs {
Expand Down
2 changes: 1 addition & 1 deletion src/code/geo2d/ang2pi_pp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace tifa_libs::geo {
template <class FP>
CEXP FP ang2pi_PP(point<FP> CR p1, point<FP> CR p2) {
FP res = ang_PP(p1, p2);
return is_neg(res) ? res + 2 * std::numbers::pi_v<FP> : res;
return is_neg(res) ? res + 2 * pi_v<FP> : res;
}

} // namespace tifa_libs::geo
Expand Down
49 changes: 49 additions & 0 deletions src/code/geo2d/any_ins_ss.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef TIFALIBS_GEO2D_ANY_INS_SS
#define TIFALIBS_GEO2D_ANY_INS_SS

#include "ins_ll.hpp"
#include "is_ins_sl.hpp"

namespace tifa_libs::geo {

// judge if any two segments are intersected
template <class FP>
CEXP bool any_ins_Ss(vec<line<FP>> CR ss) {
if (ss.empty()) return false;
using seq_t = std::tuple<FP, int, line<FP>>;
const auto seqcmp = [](seq_t CR u, seq_t CR v) {
auto [u0, u1, u2] = u;
auto [v0, v1, v2] = v;
if (is_eq(u0, v0)) return u1 == v1 ? u2 < v2 : u1 < v1;
return is_lt(u0, v0);
};
vec<seq_t> seq;
for (auto seg : ss) {
if (is_gt(seg.l.x, seg.r.x)) swap(seg.l, seg.r);
seq.emplace_back(seg.l.x, 0, seg), seq.emplace_back(seg.r.x, 1, seg);
}
std::ranges::sort(seq, seqcmp);
FP x_now;
auto cmp = [&](line<FP> CR u, line<FP> CR v) {
if (is_eq(u.l.x, u.r.x) || is_eq(v.l.x, v.r.x)) return is_lt(u.l.y, v.l.y);
return is_lt(((x_now - u.l.x) * (u.r.y - u.l.y) + u.l.y * (u.r.x - u.l.x)) * (v.r.x - v.l.x), ((x_now - v.l.x) * (v.r.y - v.l.y) + v.l.y * (v.r.x - v.l.x)) * (u.r.x - u.l.x));
};
std::multiset<line<FP>, decltype(cmp)> s{cmp};
for (auto CR[x, o, seg] : seq) {
x_now = x;
auto it = s.lower_bound(seg);
if (!o) {
if (it != s.end() && is_ins_SL(seg, *it)) return 1;
if (it != s.begin() && is_ins_SL(seg, *prev(it))) return 1;
s.insert(seg);
} else {
if (next(it) != s.end() && it != s.begin() && is_ins_LL(*prev(it), *next(it))) return 1;
s.erase(it);
}
}
return 0;
}

} // namespace tifa_libs::geo

#endif
4 changes: 2 additions & 2 deletions src/code/geo2d/area_cc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace tifa_libs::geo {
template <class FP>
CEXP FP area_CC(circle<FP> CR c1, circle<FP> CR c2) {
auto relation = relation_CC(c1, c2);
if (relation == RELCC::lyingout_cc || relation == RELCC::touchex_cc) return FP{};
if (relation == RELCC::lyingin_cc || relation == RELCC::touchin_cc) return min(c1.area(), c2.area());
if (relation == lyingout_cc || relation == touchex_cc) return FP{};
if (relation == lyingin_cc || relation == touchin_cc) return min(c1.area(), c2.area());
FP d = dist_PP(c1.o, c2.o);
return c1.crown_area(std::acos((c1.r * c1.r - c2.r * c2.r + d * d) / (2 * c1.r * d)) * 2) + c2.crown_area(std::acos((c2.r * c2.r - c1.r * c1.r + d * d) / (2 * c2.r * d)) * 2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/code/geo2d/area_poc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace tifa_libs::geo {
template <class FP>
CEXP FP area_PoC(polygon<FP> CR po, circle<FP> CR c) {
math::kahan<FP> ans{};
u32 sz = (u32)po.vs.size();
u32 sz = po.size();
if (sz < 3) return ans;
flt_ (u32, i, 0, sz) ans += sarea_CT(c, po[i], po[po.next(i)]);
return abs<FP>(ans);
Expand Down
Loading

0 comments on commit cbd71da

Please sign in to comment.