Files
teamnote/2025fall/main.tex
2026-06-03 09:36:52 +09:00

1069 lines
47 KiB
TeX

\documentclass[landscape, 8pt, a4paper, oneside]{extarticle}
% \documentclass[portrait, 8pt, a4paper, oneside, twocolumn]{extarticle}
\usepackage{teamnote}
\usepackage[hangul]{kotex}
\usepackage[most]{tcolorbox}
\usepackage{multirow}
\usepackage{adjustbox}
\usepackage{subfiles}
\usepackage{amsmath}
\usepackage{etoolbox}
\AtBeginEnvironment{align*}{%
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{enumitem}
\setlistdepth{9}
\newlist{IdeaNote}{enumerate}{6}
\setlist[IdeaNote]{topsep=0pt,itemsep=-1ex,partopsep=1ex,parsep=1ex}
\setlist[IdeaNote, 1]{label= \Roman*. }
\setlist[IdeaNote, 2]{label= \Alph*. }
\setlist[IdeaNote, 3]{label= \arabic*. }
\setlist[IdeaNote, 4]{label= \roman*) }
\setlist[IdeaNote, 5]{label= \alph*) }
\setlist[IdeaNote, 6]{label= \arabic*) }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{multicol}
\setlength\columnseprule{0.5pt}
\teamnote{POSTECH}{ConSpirito}{}{ICPC Seoul Regional}
\ShowUsage
\ShowComplexity
\HideAuthor
\begin{document}
\begin{multicols}{3}
\maketitlepage
\par\noindent\rule{\columnwidth}{0.4pt}
\section{Have you...}
\subsection{tried...}
\begin{itemize}
\item \textcolor{red}{\textbf{Reading the problem once more?}}
\item doubting ``obvious" things?
\item writing obivous things?
\item radical greedy approach?
\item thinking in reverse direction?
\item a greedy algorithm?
\item network flow when your greedy algorithms stuck?
\item a dynamic programming?
\item checking the range of answer?
\item random algorithm?
\item graph modeling using states?
\item inverting state only on odd indexes?
\item calculating error bound on a real number usage?
\end{itemize}
\subsection{checked...}
\begin{itemize}
\item \textcolor{red}{\textbf{you have read the statement correctly?}}
\item typo copying the team note?
\item initialization on multiple test case problem?
\item additional information from the problem?
\item undefined behavior?
\item overflow?
\item function without return value?
\item real number error?
\item implicit conversion?
\item comparison between signed and unsigned integer?
\end{itemize}
\subsection{Geometry?}
\begin{itemize}
\item 1 point? 2 points? line? 3 or more points on a line?
\item parallel line? points on line? circle?
\item degenerate case? endpoints of segment?
\end{itemize}
% \pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Algorithmic Idea Note}
When you don't have any ideas, please bruteforce it.
\begin{tcolorbox}[breakable, enhanced, sharp corners, colback=white, colframe=black, boxrule=1pt, left=0pt]
\begin{IdeaNote}
\item Complete Search: Backtracking \& Pruning
\item Math
\begin{IdeaNote}
\item Number Theory
\begin{IdeaNote}
\item Prime Number
\begin{IdeaNote}
\item Sieve of Eratosthenes, Prime Factorization
\item Fast Prime Verdict; Millar-Rabin
\item Fast Prime Factorization; Pollad Rho
\item Primitive Root
\end{IdeaNote}
\item Extended Euclidean Algorithm; Diophantos Equation
\item Chinese Remainder Theorem
\item Harmonic Lemma
\item Floor Sum (Sum of Rational Arithmetic Sequence)
\item Several Sieves
\end{IdeaNote}
\item Linear Programming
\begin{IdeaNote}
\item Solve (some) LP with Shortest Path
\end{IdeaNote}
\item FFT \& Polynomials
\begin{IdeaNote}
\item FFT : Convolution
\begin{IdeaNote}
\item High precision FFT with modulo 1e9+7
\end{IdeaNote}
\item NTT : Number Theoretic Tranform
\item Quotient Ring (Formal Power Series)
\begin{IdeaNote}
\item Multiplication
\item FPS : Inverse / Division
\item Integration / Differentiation
\item FPS : Logarithm / Exponentiation
\item FPS : Power of Polynomial
\item Division - Quotient \& Remainder
\item Polynomial Taylor Shift
\item Multipoint Evaluation
\end{IdeaNote}
\end{IdeaNote}
\item Combinatorics
\begin{IdeaNote}
\item Labeled Combinatorial Target
\item The Twelvefold Way (12정도)
\item Generating Function
\begin{IdeaNote}
\item OGF(Ordinary Generating Function)
\item EGF(Exponentional Generating Function)
\item DGF?(Dirichlet Genetration Function) : Number Theory
\end{IdeaNote}
\item Umbral Calculus
\end{IdeaNote}
\end{IdeaNote}
\item Linear Algebra
\item Geometry
\begin{IdeaNote}
\item Basic Tools
\begin{IdeaNote}
\item Outer Product (CCW)
\item Sorting by Polar
\item Segment Intersection
\item Closest Point
\item Furthest Point
\end{IdeaNote}
\item Convex Polygon (Convex Hull)
\begin{IdeaNote}
\item Convex Hull Construction
\item Convex Layer
\item Rotating Calipers
\item Point Containment
\item Tangent to convex polygon
\item Inner and Outer Tangent of two Convex's
\end{IdeaNote}
\item General Polygon
\item Half Plane Intersection
\item Bulldozer Trick
\item Delaunay Triangulation : Voronoi diagram
\end{IdeaNote}
\item Greedy
\begin{IdeaNote}
\item Rearrangement Inequality
\end{IdeaNote}
\item DP
\begin{IdeaNote}
\item DP Optimization
\begin{IdeaNote}
\item Convex Hull Trick
\item Alien's Trick (Lagrangian Relaxation)
\item Slope Trick
\end{IdeaNote}
\end{IdeaNote}
\item String
\begin{IdeaNote}
\item KMP(Knuth-Morris-Pratt), Z, Manacher Algorithm
\item Trie
\item Aho-Corasick
\item Suffix Array \& LCP Array
\item Eertree
\item Wavelet Tree
\end{IdeaNote}
\item Graph
\begin{IdeaNote}
\item Searching : DFS/BFS
\item DAG(Directed Acyclic Graph) : Topological Sorting
\item MST(Minimum Spanning Tree)
\begin{IdeaNote}
\item Kruskal Algorithm
\item Prim Algorithm
\item Euclidian MST
\end{IdeaNote}
\item Shortest Path
\begin{IdeaNote}
\item Dijkstra Algorithm
\item Bellman-Ford Algorithm
\item Floyd-Warshall Algorithm
\item Shortest Path DAG
\end{IdeaNote}
\item Connectivity
\begin{IdeaNote}
\item Offline Dynamic Connectivity (Odc)
\item Online Dynamic Connectivity
\begin{IdeaNote}
\item Euler Tour Tree
\item Top Tree
\end{IdeaNote}
\end{IdeaNote}
\item DFS tree
\begin{IdeaNote}
\item SCC(Strongly Connected Component)
\begin{IdeaNote}
\item Graph Compression
\item 2-SAT Problem
\item Offline Incremental SCC
\end{IdeaNote}
\item BCC (BiConnected Component)
\begin{IdeaNote}
\item Block Cut Tree
\item Cactus Graph
\end{IdeaNote}
\item Articulation Points and Bridges
\end{IdeaNote}
\item Network Flow
\begin{IdeaNote}
\item Bipartite Matching
\begin{IdeaNote}
\item Hall's Marrage Theorem
\item Minimum Vertex Cover on Bipartite
\item Maximum Independent Set on Bipartite
\item Minimum Path Cover on DAG
\item Maximum Antichain on DAG
\end{IdeaNote}
\item Ford-Fulkerson/Edmonds-Karp Algorithm
\item Dinic's Algorithm
\item Push-Relabel Algorithm
\item MCMF(Minimum Cost Maximum Flow)
\item Minimum s-t Cut = Maximum Flow
\item Global Cut(Stoer-Wagner Algorithm)
\item Circulation
\item General Matching
\end{IdeaNote}
\item Treewidth
\end{IdeaNote}
\item Tree
\begin{IdeaNote}
\item LCA(Lowest Common Ancestor)
\item Heavy-Light Decomposition
\item Centroid Decomposition
\item Link-Cut Tree
\end{IdeaNote}
\item Data Structure
\begin{IdeaNote}
\item C++ Standard Library
\begin{IdeaNote}
\item Stack, Queue, List, Vector, Deque
\item Priority Queue; Heap
\item Set, Map : Binary Search Tree
\item Unordered Set, Unordered Map : Hashing
\item PBDS(Policy-Based Data Structure)
\item Rope (Cord)
\end{IdeaNote}
\item Disjoint Set (Unoin-Find structure)
\begin{IdeaNote}
\item Union by Rank / Path Compression
\item UF with LCA (Making Root)
\item UF with Edge Weight
\item UF with Unjoining
\begin{IdeaNote}
\item Unjoin from latest (Stack undoing)
\item Unjoin from earliest (Queue undoing)
\item Unjoin by Priority (Priority undoing)
\end{IdeaNote}
\end{IdeaNote}
\item Sparse Table
\item Range Query Structure
\begin{IdeaNote}
\item Square Root Decomposition
\item Fenwick Tree
\item Segment Tree
\begin{IdeaNote}
\item Lazy Propagation \& Generalization
\item 금광 ST (Maximum Adjacent Sum of Given Range)
\item PST (Persistent Segment Tree)
\item MST (Merge Sort Tree)
\item Segment Tree on Tree (HLD)
\item Li-Chao Tree (Segment Add Get Min)
\item ST Beats
\item Kinetic ST
\end{IdeaNote}
\item Splay Tree
\begin{IdeaNote}
\item Range Reverse / Range Shift
\end{IdeaNote}
\end{IdeaNote}
\end{IdeaNote}
\item Sorting \& Searching
\begin{IdeaNote}
\item Sorting
\item Searching
\begin{IdeaNote}
\item Binary Search : Monotone Sequence / function
\begin{IdeaNote}
\item Lower bount / Upper bound
\item LIS (Longest Increasing Subsequence)
\item PBS (Parallel Binary Search)
\end{IdeaNote}
\item Ternary Search : Unimodal Sequence / function
\begin{IdeaNote}
\item Fibonacci Search (Golden Ratio Search)
\end{IdeaNote}
\end{IdeaNote}
\end{IdeaNote}
\item Numerical Analysis
\begin{IdeaNote}
\item Numerical Differentiation
\item Gradient Descent
\end{IdeaNote}
\item Technic
\begin{IdeaNote}
\item Coordinate Compression
\item Two Pointer/Sliding Window
\item Sweeping
\item Meet in the Middle
\item Bitmasking
\item Small to Large
\item Randomization
\begin{IdeaNote}
\item Verifying Matrix Multiplication
\end{IdeaNote}
\item Query Technic
\begin{IdeaNote}
\item Offline Query
\begin{IdeaNote}
\item Mo's Algorithm
\end{IdeaNote}
\end{IdeaNote}
\end{IdeaNote}
\end{IdeaNote}
\end{tcolorbox}
\Algorithm{POROGOD}{}{}{cpp}{source/poro.cpp}
\pagebreak
% \Algorithm{astilate}{}{}{cpp}{source/Fundemental.cpp}
\subsection{Tips for Inequality with Rational Number}
Let $A$, $B$, $x$, $n$ be integer, and operator `/' means floor division(quotient).
\begin{align*}
Ax \leqslant B & \Leftrightarrow x \leqslant B/A \\
Ax < B & \Leftrightarrow x \leqslant (B-1)/A \\
Ax \geqslant B & \Leftrightarrow x \geqslant (B+A-1)/A \\
Ax > B & \Leftrightarrow x \geqslant B/A+1 \\ \\
x < n & \Leftrightarrow x+1\leqslant n
\end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Math}
\subfile{source/Math/math}
\subsection{Prime Number}
\subsubsection{Distribution of Prime Number}
\begin{center}
\begin{tabular}{|
>{\columncolor[HTML]{BFBFBF}}c |c|
>{\columncolor[HTML]{BFBFBF}}c |c|
>{\columncolor[HTML]{BFBFBF}}c |c|}
\hline
1e2 & 25 & 1e6 & 78,498 & 1e10 & \textless 5e8 \\ \hline
1e3 & 168 & 1e7 & 664,579 & 1e11 & \textless 5e9 \\ \hline
1e4 & 1,229 & 1e8 & \textless 6e6 & 1e12 & \textless 4e10 \\ \hline
1e5 & 9,592 & 1e9 & \textless 6e7 & 1e13 & \textless 4e11 \\ \hline
\end{tabular}
\end{center}
\subsubsection{Prime Gap}
\begin{align*}
2 \cdot 10^{5} \text{ 이하의 소수 간극 } &\le 100\\
2^{32} \text{ 이하의 소수 간극 } &\le 464 \\
2^{64} \text{ 이하의 소수 간극 } &\le 1550
\end{align*}
\Algorithm{Miller-Rabin Algorithm}
{\texttt{is\_p(X)} : returns true if $X$ is prime, otherwise false.
\begin{align*}
\text{ When } X \le 2^{32}, D &= \{2, 7, 61\} \text{ is sufficient; } \\
X \le 2^{64}, D &= \{p | p \text{ is prime}, p \le 37 \} \text{ is sufficient.}
\end{align*}}
{$\mathcal O (\log^3 X)$}
{cpp}
{source/Math/MillerRabin.cpp}
\Algorithm{Pollad Rho Algorithm}
{ \texttt{po\_rho(N)} : returns array of prime factors of X.}
{$\mathcal O (N^{1/4})$}
{cpp}
{source/Math/PolladRho.cpp}
\Algorithm{Primitive Root}
{Calculate one of the primitive roots of given prime.}
{}{cpp}
{source/Math/PrimitiveRoot.cpp}
\Algorithm{Diopantos Equation(Extended Euclidian Algorithm)}
{\texttt{diophantos(a, b)} : return one integer solution of $ax+by=1$, satisfying $0 \le x < b$. }
{$\mathcal O \left(\log \left( \max(a, b) \right) \right)$}
{cpp}
{source/Math/Diophantos.cpp}
\Algorithm{Chinese Remainder Theorem}
{\texttt{crt(pll p, pll q)} : return \texttt{pll r}, satisfying follows:
\begin{align*}
x &\equiv \texttt{p.fi} \mod \texttt{p.se} \\
\text{and } x &\equiv \texttt{q.fi} \mod \texttt{q.se} \\
\leftrightarrow x &\equiv \texttt{r.fi} \mod \texttt{r.se}
\end{align*}
If there's no such \texttt{r}, return $\{-1, -1\}$.
}
{$\mathcal O(\log A)$}
{cpp}
{source/Math/CRT.cpp}
\Algorithm{Harmonic Lemma}
{\texttt{f(N)} : return the value
$$\sum_{i=1}^{N} \left\lfloor \frac{N}{i} \right\rfloor = \left\lfloor \frac{N}{1}\right\rfloor + \left\lfloor \frac{N}{2} \right\rfloor + \cdots + \left\lfloor \frac{N}{N}\right\rfloor $$
Using the fact that $\left\lfloor \frac{N}{x} \right\rfloor$ has $\mathcal O(\sqrt N)$ different values.}
{$\mathcal O(\sqrt N )$}
{cpp}
{source/Math/Harmonic.cpp}
\Algorithm{Floor Sum (Sum of Floor of Rational Arithmetic Sequence)}
{\texttt{floor\_sum(A, B, C, N)} : return the value
$$\sum_{x=0}^{N-1} \left\lfloor \frac{Ax+B}{C} \right\rfloor $$}
{$\mathcal O(\log N)$}
{cpp}
{source/Math/FloorSum.cpp}
\Algorithm{FFT - Convolution}
{}
{$\mathcal O (N\log N)$}
{cpp}
{source/Math/FFTConv.cpp}
\Algorithm{NTT - Number Theoretic Transform}
{helloworld}
{}
{cpp}
{source/Math/NTT.cpp}
\subsubsection{Good prime numbers to run NTT}
\begin{center}
\begin{adjustbox}{width=0.8\columnwidth}
\begin{tabular}{|c|c|
>{\columncolor[HTML]{C0C0C0}}l |}
\hline
595 591 169 & 71\textless{}\textless{}23|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
645 922 817 & 77\textless{}\textless{}23|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
897 581 057 & 107\textless{}\textless{}23|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
998 244 353 & 119\textless{}\textless{}23|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
1 300 234 241 & 155\textless{}\textless{}23|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
1 224 736 769 & 73\textless{}\textless{}24|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
2 130 706 433 & 127\textless{}\textless{}24|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
167 772 161 & 5\textless{}\textless{}25|1 & \cellcolor[HTML]{C0C0C0} \\ \cline{1-2}
469 762 049 & 7\textless{}\textless{}26|1 & \multirow{-9}{*}{\cellcolor[HTML]{C0C0C0}$\omega$ = 3} \\ \hline
\end{tabular}
\end{adjustbox}
\end{center}
\Algorithm{Polynomial (Formal Power Series)}
{}
{}
{cpp}
{source/Math/Polynomial.cpp}
\subsection{Combinatorics}
\subsubsection{Labeled Combinatorial Target}
\begin{itemize}
\item Permutation, Combination (with, w/o repetition)
\begin{itemize}
\item Permutation $_nP_r = \frac{n!}{r!(n-r)!}$
\item Combination $_nC_r = \binom n k = \frac{n!}{r!}$
\item Permutation with repetition $_n\Pi_r = n^r$
\item Combination with repetition $_nH_r = _{n+r-1}C_r$
\end{itemize}
\item Catalan Number $C_n$ : the number of regular bracket string of length $2n$.
\begin{itemize}
\item $C_n = \frac{1}{n+1}\binom {2n}n$
\item $C_n : 1, 1, 2, 5, 14, 42, 132,429,1430,\cdots$ (from index 0)
\item OGF of $C_n$ : $c(x) = 1+xc(x)^2, c(c) = \frac{1-\sqrt{1-4x}}{2x}$
\item Catalan's triangle $C(n, k)$ : the number of string with $n$ X's, $k$ Y's, where the number of Y's is not greater than the number of X's when written down the string.
\begin{itemize}
\item i.e. $C(4, 3)$ : XXXXYYY, XXYXYYX are OK, but XXYYYXX is not OK.
\item $C(n, k) = \binom{n+k}{k} - \binom{n+k}{k-1} = \frac{n-k+1}{n+1}\binom{n+k}{k}$
\item We can give the condition relax : $C_m(n, k)$ : the number of string with $n$ X's, $k$ Y's, where the number of Y's is not greater than (the number of X's) + $m$ when written down the string.
\item $C_m(n, k) = \binom{n+k}{k}-\binom{n+k}{k-m}$ when $m\leqslant k \leqslant n+m-1$.
\item $C_1(n, k) = C(n, k)$
\end{itemize}
\end{itemize}
\item Derangement(교란순열) $D_n$ : the number of permutation of length $n$ which $\forall i\;p_i \neq i$.
\begin{itemize}
\item $D_n : 1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496,1334961 \cdots$ (from index 0)
\item EGF of $D_n$ : $D(x) = \sum_{n=0} \frac{D_n}{n!}x^n = \frac{e^{-x}}{1-x}$
\end{itemize}
\item Stirling Number of the 1st/2nd kind.
\begin{itemize}
\item Unsigned Stirling Number of the 1st kind $c(n, k) = \genfrac{[}{]}{0pt}{}{n}{k}$ : the number of permutation of length n with k disjoint cycles.
\begin{itemize}
\item $c(n+1, k) = n \times c(n, k) + c(n, k-1)$
\item with boundary condition $c(0, 0) = 1, c(n, 0) = c(0, k) = 0 \; \forall n, k>0$
\item $c(n, k)$
\begin{itemize}
\item $c(0, 0) = 1$; $c(x_{\neq0}, 0) = 0$; $c(x, x) = 1$
\item $c(x, x) = 1$
\item $c(5, *) = \{0, 24, 50, 35, 10 1\}$
\item $c(6, *) = \{0, 120, 274, 225, 85, 15, 1\}$
\end{itemize}
% \begin{tabular}{|
% >{\columncolor[HTML]{ECECEC}}r |
% >{\columncolor[HTML]{F8F9FA}}r |r|r|r|l|l|l|}
% \hline
% \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} \textit{n\textbackslash{}k}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{0}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{1}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{2}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{3}} & \multicolumn{1}{r|}{\cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{4}}} & \multicolumn{1}{r|}{\cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{5}}} & \multicolumn{1}{r|}{\cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{6}}} \\ \hline
% {\color[HTML]{202122} \textbf{0}} & {\color[HTML]{202122} 1} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & & & \\ \hline
% {\color[HTML]{202122} \textbf{1}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & & & \\ \hline
% {\color[HTML]{202122} \textbf{2}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \multicolumn{1}{l|}{} & & & \\ \hline
% {\color[HTML]{202122} \textbf{3}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 2} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 3} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & & & \\ \hline
% {\color[HTML]{202122} \textbf{4}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 6} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 11} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 6} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1}} & & \\ \hline
% {\color[HTML]{202122} \textbf{5}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 24} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 50} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 35} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 10}} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1}} & \\ \hline
% {\color[HTML]{202122} \textbf{6}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 120} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 274} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 225} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 85}} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 15}} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1}} \\ \hline
% \end{tabular}
\item OGF of $\genfrac{[}{]}{0pt}{}{n}{k}$ : for fixed $n$, $\sum_{k=0}^n \genfrac{[}{]}{0pt}{}{n}{k} x^k = x(x+1)(x+2)\cdots(x+n-1)$ : we can calculate it by polynomial shift \& divide and conquer
\item EGF of $\genfrac{[}{]}{0pt}{}{n}{k}$ : for fixed $k$, $\sum_{n=k}^\infty \genfrac{[}{]}{0pt}{}{n}{k} \frac{x^n}{n!} = \frac{(-\log(1-z))^k}{k!} $
\item Signed Stirling Number of the 1st kind $s(n, k) = (-1)^{n-k}c(n, k)$
\item EGF of $s(n, k)$ : for fixed $k$, $\sum_{n=k}^\infty s(n, k) \frac{x^n}{n!} = \frac{(\log(1+z))^k}{k!} $
\end{itemize}
\item Stirling Number of the 2nd kind $S(n, k) = \genfrac{\{}{\}}{0pt}{}{n}{k}$ : the number of partition of $n$ labeled objects into $k$ nonempty unlabelled subsets.
\begin{itemize}
\item $S(n, k) = \frac{1}{k!}\sum_{i=0}^k(-1)^{k-i}\binom{k}{i}i^n$
\item $S(n,k)=S(n - 1,k - 1)+k\cdot S(n - 1,k)$
\item $S(n, k)$
\begin{itemize}
\item $S(0, 0) = 1$; $S(x_{\neq 0}, 0) = 0$; $S(x, x) = 1$
\item $S(5, *) = \{0, 1, 15, 25, 10, 1\}$
\item $S(6, *) = \{0, 1, 31, 90, 65, 15, 1\}$
\end{itemize}
% \begin{tabular}{|
% >{\columncolor[HTML]{ECECEC}}r |
% >{\columncolor[HTML]{F8F9FA}}r |r|r|r|l|l|l|}
% \hline
% \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} \textit{\textbf{n\textbackslash{}k}}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{0}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{1}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{2}} & \cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{3}} & \multicolumn{1}{r|}{\cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{4}}} & \multicolumn{1}{r|}{\cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{5}}} & \multicolumn{1}{r|}{\cellcolor[HTML]{ECECEC}{\color[HTML]{202122} \textbf{6}}} \\ \hline
% {\color[HTML]{202122} \textbf{0}} & {\color[HTML]{202122} 1} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & & & \\ \hline
% {\color[HTML]{202122} \textbf{1}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & & & \\ \hline
% {\color[HTML]{202122} \textbf{2}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \multicolumn{1}{l|}{} & & & \\ \hline
% {\color[HTML]{202122} \textbf{3}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 3} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & & & \\ \hline
% {\color[HTML]{202122} \textbf{4}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 7} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 6} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1}} & & \\ \hline
% {\color[HTML]{202122} \textbf{5}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 15} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 25} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 10}} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1}} & \\ \hline
% {\color[HTML]{202122} \textbf{6}} & {\color[HTML]{202122} 0} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 31} & \cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 90} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 65}} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 15}} & \multicolumn{1}{r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} 1}} \\ \hline
% \end{tabular}
\item OGF of $\genfrac{\{}{\}}{0pt}{}{n}{k}$ : for fixed $n$, $\sum_{k=0}^n\genfrac{\{}{\}}{0pt}{}{n}{k}x^k=T_n(x)$, where $T_n(x) = e^{-x}\sum_{k=0}^{\infty}\frac{k^n}{k!}x^k$ is Touchard Polynomials.
\item EGF of $\genfrac{\{}{\}}{0pt}{}{n}{k}$ : for fixed $k$, $\sum_{n=k}^\infty\genfrac{\{}{\}}{0pt}{}{n}{k}\frac{x^n}{n!}=\frac{(e^x-1)^k}{k!}$
\end{itemize}
\end{itemize}
\item Bell Number $B_n$ : the number of partition of set with size $n$.
\begin{itemize}
\item i.e. partitionize $\{a, b, c\}$ is $\{\{a\}, \{b\}, \{c\}\}, \{\{a , b\}, \{c\}\}$, $\{\{b, c\}, \{a\}\}, \{\{c, a\}, \{b\}\}, \{\{a, b, c\}\}$. Therefore, $B_3 = 5$.
\item $B_n : 1,1,2,5,15,52,203,877,4140,\cdots$ (from index 0)
\item $B_n = \sum_{k=0}^n\genfrac{\{}{\}}{0pt}{}{n}{k}$ (2nd kind of stirling number)
\item EGF of $B_n$ : $B(x) = \sum_{n=0}\frac{B_n}{n!}x^n=e^{e^x-1}$
\item Ordered Bell Number(Fubini Number) $a_n$ : the number of distinct weak ordering on a set of n elements.
\begin{itemize}
\item $a_n : 1, 1, 3, 13, 75, 541, 4683, 47293, 545835, 7087261, \cdots$
\item $a_n = \sum_{k=0}^nk!\genfrac{\{}{\}}{0pt}{}{n}{k}$ (stirling number of the 2nd kind)
\item EGF of $a_n$ : $a(x) = \sum_{n=0}^\infty \frac{a_n}{n!}x^n = \frac{1}{2-e^x}$
\end{itemize}
\end{itemize}
\item Integer Partition $P(n, k)$ : the number of partitions of $n$ into exactly $k$ parts.
\begin{itemize}
\item i.e. $P(4, 2) = 2$ since $4 = 1+3 = 2+2$
\item we also say $P(n) = \sum_{k=1}^{n}P(n, k)$
\item $P(n, k)$
\begin{itemize}
\item $P(x, 1) = P(x, x) = 1$
\item $P(8, *) = \{1, 4, 5, 5, 3, 2, 1, 1\}$
\item $P(9, *) = \{1, 4, 7, 6, 5, 3, 2, 1, 1\}$
\end{itemize}
\item $P(n) = \{1, 2, 3, 5, 7, 11, 15, 22, 30, 42\}$
% \begin{tabular}{|
% >{\columncolor[HTML]{EAECF0}}c |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |
% >{\columncolor[HTML]{F8F9FA}}l |}
% \hline
% \multicolumn{1}{|r|}{\cellcolor[HTML]{F8F9FA}{\color[HTML]{202122} \textit{\textbf{n\textbackslash{}k}}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{1}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{2}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{3}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{4}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{5}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{6}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{7}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{8}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{9}}} \\ \hline
% {\color[HTML]{202122} \textbf{1}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{2}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{3}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{4}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{5}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{6}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 3} & {\color[HTML]{202122} 3} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{7}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 3} & {\color[HTML]{202122} 4} & {\color[HTML]{202122} 3} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{8}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 4} & {\color[HTML]{202122} 5} & {\color[HTML]{202122} 5} & {\color[HTML]{202122} 3} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} } \\ \hline
% {\color[HTML]{202122} \textbf{9}} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 4} & {\color[HTML]{202122} 7} & {\color[HTML]{202122} 6} & {\color[HTML]{202122} 5} & {\color[HTML]{202122} 3} & {\color[HTML]{202122} 2} & {\color[HTML]{202122} 1} & {\color[HTML]{202122} 1} \\ \hline
% \end{tabular}
\end{itemize}
\item 12정도(the Twelvefold Way) : the number of functions \\
(Domain $|N| = n$, Codomain $|X| = x$)\\
\begin{tabular}{|
>{\columncolor[HTML]{F8F9FA}}c |c|c|c|}
\hline
\cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textit{\textbf{$f$-class}}} & \cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{Any $f$}} & \cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{Injective}} & \cellcolor[HTML]{EAECF0}{\color[HTML]{202122} \textbf{Surjective}} \\ \hline
{\color[HTML]{202122} \textbf{Distinct $f$}} & \textit{$_n\Pi_x$} & \textit{$_xP_n$} & $x!\genfrac{\{}{\}}{0pt}{}{n}{k}$ \\ \hline
{\color[HTML]{202122} \textit{\textbf{\begin{tabular}[c]{@{}c@{}}$S_n$ orbits\\ $f \circ S_n$\end{tabular}}}} & \textit{$_xH_n$} & \textit{$_xC_n$} & $_{n-1}C_{n-x}$ \\ \hline
{\color[HTML]{202122} \textit{\textbf{\begin{tabular}[c]{@{}c@{}}$S_x$ orbits\\ $S_x \circ f$\end{tabular}}}} & $\sum_{k=0}^x \genfrac{\{}{\}}{0pt}{}{n}{k}$ & $[n \leqslant x]$ & $\genfrac{\{}{\}}{0pt}{}{n}{k}$ \\ \hline
{\color[HTML]{202122} \textit{\textbf{\begin{tabular}[c]{@{}c@{}}$S_n\times S_x$ orbits\\ $S_x \circ f \circ S_n$\end{tabular}}}} & $P(n+x, x)$ & $[n \leqslant x]$ & $P(n, x)$ \\ \hline
\end{tabular}
\end{itemize}
% \Algorithm{General Lucas Comb}
% {}
% {}
% {cpp}
% {source/Math/general_lucas.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Linear Algebra}
\Algorithm{Matrix}
{}
{}
{cpp}
{"source/Linear Algebra/Matrix.cpp"}
\Algorithm{Berlekamp Massey}
{}
{}
{cpp}
{"source/Linear Algebra/BerlekampMassey.cpp"}
\Algorithm{XOR Basis}
{}
{}
{cpp}
{"source/Linear Algebra/XORBasis.cpp"}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Geometry}
\Algorithm{Mindset}
{}
{}
{cpp}
{source/Geometry/Mindset.cpp}
\Algorithm{Point in Convex Polygon}
{\texttt{isunder(upper\_hull[], (length of upper\_hull), x)} : return true if $x$(point) is under upper\_hull, otherwise false;
\texttt{isunder(lower\_hull[], (length of lower\_hull), x, true)} : return true if $x$(point) is over lower\_hull, otherwise false.
Point in Polygon : isunder(upper, u, x) \&\& isupper(lower, u, x, true)}
{}
{cpp}
{source/Geometry/PointInConvexPolygon.cpp}
\Algorithm{Geo}
{}
{}
{cpp}
{source/Geometry/Geo.cpp}
\Algorithm{Half-Plane Intersection}
{}
{}
{cpp}
{source/Geometry/HPI.cpp}
\Algorithm{Bulldozer}
{}
{}
{cpp}
{source/Geometry/Bulldozer.cpp}
% \Algorithm{kactl templete}
% {}
% {}
% {cpp}
% {source/Geometry/geometry_kaere.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Greedy}
\subsection{Rearrange Inequality - Extensions}
Let $A_i, B_i$ be non-decreasing sequence of length $n$, and $p$ be some permutation, and let $inc := (1, 2, \dots, n-1, n), \;dec := (n, n-1, \dots, 2, 1)$.
\begin{align*}
S(p) &= \sum_{i=1}^n A_i B_{p_i}
&& \text{ maximize } S &&&\Rightarrow p : inc&&&&\\
& && \text{ minimize } S &&&\Rightarrow p:dec&&&&\\
P_{max}(p) &= \max_i(A_iB_{p_i})
&& \text{ minimize } P_{max} &&&\Rightarrow p : dec&&&&\\
P_{min}(p) &= \min_i(A_iB_{p_i})
&& \text{ maximize } P_{min} &&&\Rightarrow p:dec&&&&\\
A_{max}(p) &= \max_i(A_i+B_{p_i}) && \text
{ minimize } A_{max} &&& \Rightarrow p:dec&&&&\\
A_{min}(p) &= \min_i(A_i+B_{p_i}) && \text{ maximize } A_{min} &&& \Rightarrow p:dec&&&&\\
D_{max}(p) &= \max_i|A_i-B_{p_i}| && \text{ minimize } D_{max} &&& \Rightarrow p:inc&&&&\\
D_{min}(p) &= \min_i|A_i-B_{p_i}| && \text{ maximize } D_{min} &&& \Rightarrow p:?&&&&\\
\end{align*}
\begin{align*}
\text{ Permutate } A \text{ s.t.} \text{ maximize } & \sum_{i=1}^n {A_i A_{i+1}} \;(\text{Let } A_{n+1} = A_1) \\ &\Rightarrow \text{ Pendulum Arrangement }
\end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{DP}
\Algorithm{LIS}
{}{}{cpp}{source/DP/LIS.cpp}
\subsection{DP Optimization}
\subsubsection{Convex Hull Optimization}
\begin{align*}
\text{ Recurrence : }& D[i] = \min_{j<i} { \left(B[j] \times A[i] + D[j] \right)}\\
\text{ Complexity : }& \mathcal O(N^2) \rightarrow \mathcal O(N\log N)
\end{align*}
\subsubsection{Divide and Conquer Optimization}
\begin{align*}
\text{ Recurrence : }& D[i][j] = \min_{k<i} { \left(D[i-1][k] + C[k][j]\right)}\\
\text{ Condition : }& C[i][j] \text{ is Monge } \\
(\text{ if }a \leqslant b \leqslant c \leqslant d, &\text{ then } C[a][c] + C[b][d] \leqslant C[a][d] + C[b][c] )\\
\text{ Complexity : }& \mathcal O(KN^2) \rightarrow \mathcal O(KN\log N)
\end{align*}
\inputminted[]{cpp}{source/DP/DnC.cpp}
\subsubsection{Monotone Queue Optimization}
\begin{align*}
\text{ Recurrence : }& D[i] = \min_{j<i} { \left(D[j] + C[j][i]\right)}\\
\text{ Condition : }& C[i][j] \text{ is Monge } \\
\text{ Complexity : }& \mathcal O(N^2) \rightarrow \mathcal O(N\log N)
\end{align*}
\subsubsection{Knuth's Optimization}
\begin{align*}
\text{ Recurrence : }& D[i][j] = \min_{i\leqslant k < i} { \left(D[i][k] + D[k+1][j] \right) + C[i][j] } \\
\text{ Condition : }& C[i][j] \text{ is Monge } \& \\ & C[a][d] \geqslant C[b][c] \text{ for } a \leqslant b \leqslant c \leqslant d \\
\text{ Complexity : }& \mathcal O(N^3) \rightarrow \mathcal O(N^2)
\end{align*}
구간에 대해 동적 계획법(DP)을 수행할 때, 다음과 같은 점화식이 있다고 가정합니다:
\[ a[i][j] = \min_{i < k < j} \big( a[i][k] + a[k][j] \big) + f(i, j) \]
여기서 (최소화된) 최적의 \( k \)\( i \)\( j \) 모두에 대해 증가한다고 하면, 구간의 길이에 따라 DP를 계산하며 \( a[i][j] \)에 대해 \( k = p[i][j] \)\( p[i][j-1] \)부터 \( p[i+1][j] \) 사이에서만 탐색하면 됩니다.
\subsubsection{Aliens Trick (Lagrangian relaxation)}
\begin{align*}
\text{ Recurrence : }& D[k][i] = \min_{j<i} \left( D[k-1][j] + C[j+1][i]\right)\\
\text{ Condition : }& D[x][N] \text{ is convex } ( \text{ is implied when } C[i][j] \text{ is Monge } ) \\
& \left( f(x+1)-f(x) \leqslant f(x+2)-f(x+1) \right)\\
\text{ Complexity : }& \mathcal O(KN^2) \rightarrow \mathcal O(N^2 \log |W|)
\end{align*}
\subsubsection{Slope Trick}
13323 BOJ 수열 1/2. 수열 A가 주어진다. 증가수열 B에 대해, $\sum_{i=1}^N |A_i - B_i|$를 최소화하고, 그 B를 찾아라.
\inputminted[]{cpp}{source/DP/SlopeTrick.cpp}
\Algorithm{LineContainer}
{}
{$\mathcal O(\log N)$}
{cpp}
{source/DP/LineContainer.cpp}
% \Algorithm{Line Container-GMS}
% {}
% {}
% {cpp}
% {source/DP/LineContainerGMS.cpp}
\Algorithm{SoS(Some over Subsets)}
{}
{$\mathcal O(N\cdot2^N)$}
{cpp}
{source/DP/SoS.cpp}
% \Algorithm{}
% {}
% {$\mathcal O(N?)$}
% {cpp}
% {source/}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{String}
% \Algorithm{std::string}
% {}
% {}
% {}
% {source/String/std::string.cpp}
\Algorithm{KMP}
{}
{}
{cpp}
{source/String/KMP.cpp}
\Algorithm{F, Z, M, SA(Suffix Array), LCP(Longest Common Prefix)}
{For string s(1-indexed) of length N;
\begin{align*}
\texttt{F[i] = }& \text{maximum } k<i && \text{ s.t. } s[1\dots k] = s[i-k+1 \dots i]\\
\texttt{Z[i] = }& \text{maximum } k && \text{ s.t. } s[1\dots k] = s[i \dots i+k-1]\\
\texttt{M[i] = }& \text{maximum } k && \text{ s.t. } s[i-k+1 \dots i+k-1] \text{ is palindrom.}\\
\texttt{SA[i] = }& k && \text{ s.t. } s[k\dots N] \text{ is the } i^{th} \text{ smallest of } \\
& && \{s[1\dots N],\; s[2\dots N],\; \cdots,\; s[N\dots N]\}\\
\texttt{LCP[i] = }& \text{maximum } k && \text{ s.t. } s[SA[i-1]\dots SA[i-1]+k-1]\\
& && = s[SA[i] \dots SA[i]+k-1]
\end{align*}
}
{$\mathcal O(N),\mathcal O(N),\mathcal O(N),\mathcal O(N\log N),\mathcal O(N)$, respectively}
{cpp}
{source/String/F_Z_M_SA_LCP.cpp}
\Algorithm{Aho-Corasick}
{}
{}
{cpp}
{source/String/AhoCorasick.cpp}
\Algorithm{Eertree}
{}
{}
{cpp}
{source/String/Eertree.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Graph}
\Algorithm{SCC - Tarjan Algorithm}
{\texttt{scn[i]} : SCC number of node $i$, \texttt{nscc} : the number of SCCs}
{}
{cpp}
{source/Graph/TarjanSCC.cpp}
\SubAlgorithm{2-SAT}
{For all $(x||y)$ clause, make the edge from $!x$ to $y$, and from $!y$ to $x$, and then find the SCC from graph. Check whether for all $x$, $x$ and $!x$ are not in the same SCC. To reconstruct the 2-SAT, make it false for $x$ or make it true for $!x$ if we can, in decreasing order of scn.}
{}
{cpp}
{source/Graph/2SAT.cpp}
\Algorithm{Bipartite Matching - with DFS}
{Let's say that graph is bipartite. And Let's say that one group is $A$, and the other graph is $B$. $|A|=N$, $|B|=M$. \texttt{matching(c = s)} : add one matching from $s \in A$. If successfully matched, return true; otherwise return false. \texttt{selby[i] = } store $s\in A$, s.t. $i\in B$ is matched with $s$. \\ (e.g.) \texttt{forr(i, n) ans += matching(c=i);}}
{$\mathcal O(VE)$}
{cpp}
{source/Graph/BipartiteMatching.cpp}
\subsubsection{Hall's Marriage Theorem}
For some bipartite graph $G = (A \cup B, E)$, $G$ has perfect matching if and only if for every $S \subseteq A$, $|N_G(S)| \geqslant |S|$ holds.
\subsubsection{Minimum Vertex Cover on Bipartite Graph(Kőnig's Therorem)}
On bipartite graph, $$|\texttt{Minimum Vertex Cover}| = |\texttt{Maximum Matching}|$$
To find Minimum Vertex Cover, ( \added )
\subsubsection{Maximum Independent Set on Bipartite Graph}
On bipartite graph, $$|\texttt{Maximum Independent Set}|=|V|-|\texttt{Maximum Matching}|$$
* Note : Complement of the Vertex Cover is the Independent Set.
\subsubsection{Minimum Path Cover on DAG}
Let's think about the bipartite graph, with vertex set A and B, satisfying follow property:
\begin{itemize}
\item If there's edge from node $i$ to node $j$ on DAG, then there's edge connecting $i^{th}$ node of A and $j^{th}$ node of B, and vice versa.
\end{itemize}
Then following holds:
$|\texttt{Minimum Path Cover of DAG}| = |\texttt{Maximum Matching on Bipartite Graph}|$
\subsubsection{Maximum Antichain on DAG(Dilworth's Theorem)}
On DAG, $$|\texttt{Minimum Path Cover}| = |\texttt{Maximum Antichain}|$$
\Algorithm{Dominator Tree}
{For directed graph $G = (V, E)$ and some vertex $s \in V$ which can reach every vertex in $V$, $u$ is domonator of $v$ iff $u \neq v$ and every path from $s$ to $v$ must go through $u$. Dominator tree is the tree that connects $\textrm{idom}(v)$(Immediate Dominator) and $v$.}
{}
{cpp}
{source/Graph/DominatorTree.cpp}
\Algorithm{Network Flow - Dinic}
{Construct graph with \texttt{connect(from, to, capacity, isDirected);}. Find the flow from $S$ to $T$ with \texttt{flow(S, T);}. }
{$\mathcal O(V^2E)$, but it works like magic.}
{cpp}
{source/Graph/Dinic.cpp}
\Algorithm{MCMF - with SPFA}
{Construct graph with \texttt{connect(from, to, capacity, cost);}. Find the maximum flow and corresponding minimum cost from $S$ to $T$ with \texttt{flow(S, T);}.}
{$\mathcal O(VEf)$, but it works like magic.}
{cpp}
{source/Graph/MCMF.cpp}
\Algorithm{General Matching}
{We can use Tutte matrix. First, select arbitrary prime $p$. Second, construct $T_{i,j} = \begin{cases}
r_{i,j} & \text{if } (i,j) \in E \text{ and } i < j \\
-r_{j,i} & \text{if } (i,j) \in E \text{ and } i > j \\
0 & \text{otherwise}
\end{cases}$, with $r_{i, j}$ be the random integer in $[1, p-1]$. After construct $T$, the maximum size of $G$ is $\textrm{rank}(T)/2$ with high probability.
If we want the result of matching, use:}
{$O(n^3)$}
{cpp}
{source/Graph/Matching.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Tree}
\Algorithm{HLD(Heavy Light Decomposition)}
{}
{}
{cpp}
{source/Tree/HLD.cpp}
\Algorithm{Centroid Tree}
{}
{}
{cpp}
{source/Tree/Centroid.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Data Structure}
\Algorithm{PBDS - Policy-Based Data Structure}
{}
{Equivalent to std::set}
{cpp}
{source/DS/PBDS.cpp}
% \Algorithm{rope}{}{}{cpp}{}
\Algorithm{Union and Find - Queue Undoing}
{}
{$\mathcal O(\log^2N)$}
{cpp}
{source/DS/UF_QUndo.cpp}
\Algorithm{Fenwick Tree}{}{}{cpp}
{source/DS/Fenwick.cpp}
\Algorithm{Segment Tree}
{}
{$\mathcal O(\log N)$}
{cpp}
{source/DS/SegmentTree.cpp}
% \Algorithm{Segment Tree Generalization}
% {}
% {$\mathcal O(\log N)$}
% {cpp}
% {source/DS/SegmentTree.cpp}
\Algorithm{Segment Tree Beats}
{}
{$\mathcal O(\log N)$ on updating and querying}
{cpp}
{source/DS/STBeats.cpp}
\Algorithm{Li-Chao Tree}
{}
{}
{cpp}
{source/DS/LiChaoTree.cpp}
\Algorithm{Splay Tree}
{}
{}
{cpp}
{source/DS/SplayTree.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Numerical Analysis}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Technic}
\Algorithm{Cartesian Tree}
{}
{}
{cpp}
{source/Technic/CartesianTree.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Misc}
\Algorithm{Negative Division on C/C++}
{Procedure : (1) make both dividend and divisor positive, and calc the quotient (2) decide the sign of quotient, and calc $r$ as $a-b \times q$. Following shows the floored division, not the truncated division.}
{}
{cpp}
{source/Misc/NegDiv.cpp}
\Algorithm{Fast Input}
{Fast Input with fread. Do not use with scanf, cin, or other input function. Use \texttt{forr(i, n) read(arr[i]);} instead of \texttt{forr(i, n) scanf("\%d", arr+i);}. Use \texttt{read(s+1)} instead of \texttt{scanf("\%s", s+1);}.}
{}
{cpp}
{source/Misc/FastI.cpp}
\Algorithm{MT19937 Random Number}
{}
{}
{cpp}
{source/Misc/mt19937.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
\bigskip
--- Document end ---
\end{center}
\end{multicols}
\end{document}