diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..0e91260 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-include, /home/remote/teamnote/lib/default.cpp, --std=c++23] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index f1a10df..3a685dd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,10 @@ "%DOC%" ], "env": {} - }], + } +], + // "latex-workshop.viewer.pdf.internal.host": "0.0.0.0", + "latex-workshop.view.outline.sync.viewer": true, + "latex-workshop.view.pdf.internal.urlPrefix": "https://code.spweber.com/latex-workshop-pdf", + // "latex-workshop.latex.clean.subfolder.enabled": false, } \ No newline at end of file diff --git a/lib/default.cpp b/lib/default.cpp new file mode 100644 index 0000000..c602330 --- /dev/null +++ b/lib/default.cpp @@ -0,0 +1,24 @@ +#include + +#define getint(n) int n; scanf("%d%*c", &n) +#define getll(n) long long n; scanf("%lld%*c", &n) +#define getchar(n) char n; scanf("%c%*c", &n); +#define intab getint(a); getint(b) + +#define forr(i, n) for(int i=1;i<=(n);i++) +#define fors(i, s, e) for(int i=(s); i<=(e); i++) +#define fore(i, e, s) for(int i=(e); i>=(s); i--) + +#define fi first +#define se second +#define all(v) (v).begin(), (v).end() +#define rall(v) (v).rbegin(), (v).rend() +#define pb push_back + +using namespace std; +using ll = long long; using lll = __int128_t; +using pii = pair; using pll = pair; +using vi = vector; using vl = vector; +using vii = vector; using vll = vector; + +const int N = 2e5+7, inf=1e9+7; \ No newline at end of file diff --git a/main.pdf b/main.pdf index b030c31..3db85a2 100644 Binary files a/main.pdf and b/main.pdf differ diff --git a/main.tex b/main.tex index 7f6af12..771159c 100644 --- a/main.tex +++ b/main.tex @@ -11,6 +11,10 @@ \usepackage{subfiles} \usepackage{amsmath} +\usepackage{tkz-euclide} +\usetikzlibrary{calc} + + \usepackage{etoolbox} \AtBeginEnvironment{align*}{% @@ -38,7 +42,7 @@ \usepackage{multicol} \setlength\columnseprule{0.5pt} -\teamnote{POSTECH}{ConSpirito}{}{ICPC Seoul Regional} +\teamnote{UCPC 2025 Final}{아팀명모하지}{아팀명모하지}{} \ShowUsage \ShowComplexity @@ -72,6 +76,7 @@ \item calculating error bound on a real number usage? \end{itemize} + \subsection{checked...} \begin{itemize} @@ -378,11 +383,16 @@ When you don't have any ideas, please bruteforce it. \end{tcolorbox} -\Algorithm{POROGOD}{}{}{bash}{source/poro.cpp} +\Algorithm{POROGOD}{}{}{bash}{source/poro.sh} -\pagebreak +% \pagebreak % \Algorithm{astilate}{}{}{cpp}{source/Fundemental.cpp} +\Algorithm{cy4n1de}{}{}{cpp}{source/cy4n1de.cpp} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\section{Math} \subsection{Tips for Inequality with Rational Number} Let $A$, $B$, $x$, $n$ be integer, and operator `/' means floor division(quotient). @@ -393,9 +403,7 @@ Let $A$, $B$, $x$, $n$ be integer, and operator `/' means floor division(quotien 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} @@ -485,7 +493,7 @@ $$\sum_{x=0}^{N-1} \left\lfloor \frac{Ax+B}{C} \right\rfloor $$} \Algorithm{NTT - Number Theoretic Transform} -{helloworld} +{} {} {cpp} {source/Math/NTT.cpp} @@ -760,8 +768,8 @@ D_{min}(p) &= \min_i|A_i-B_{p_i}| && \text{ maximize } D_{min} &&& \Rightarrow p %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{DP} -\Algorithm{LIS} -{}{}{cpp}{source/DP/LIS.cpp} +% \Algorithm{LIS} +% {}{}{cpp}{source/DP/LIS.cpp} \subsection{DP Optimization} @@ -871,6 +879,17 @@ D_{min}(p) &= \min_i|A_i-B_{p_i}| && \text{ maximize } D_{min} &&& \Rightarrow p {cpp} {source/String/AhoCorasick.cpp} +% % gemini flash : lyndon word, lyndon decomp를 설명해 +% \Algorithm{Duval's} +% {A string is called simple (or a Lyndon word), if it is strictly smaller than any of its own nontrivial suffixes. Examples of simple strings are a,b,ab,aab,abb,abcd,abaca, b, ab, aab, abb, abcd, abac. +% It can be shown that a string is simple, if and only if it is strictly smaller than all its nontrivial cyclic shifts. As a corollary, it can be observed that simple words are never periodic (it is not a repetition of some words for 22 or more times). +% The Lyndon decomposition of string ss is a factorization $s = w_1w_2 \ldots w_k$, where all strings $w_i$ are simple, and are in non-increasing order $w_1 \geq w_2 \geq \ldots \geq w_k$. +% Alternatively, the Lyndon decomposition of string s can be represented as $s = w_1^{p_1} w_2^{p_2} \ldots w_k^{p_k}$. Here, $p_i$ are positive integers, and $w^p_i$ denotes the string w repeated for $p_i$ times. All strings $w_i$ are simple, and are in decreasing order $w_1 > w_2 > \ldots > w_k$. The only difference is that the group of identical factors is grouped as a chunk such as $w^p_i$. +% } +% {} +% {cpp} +% {source/String/Duval.cpp} + \Algorithm{Eertree} {} {} @@ -981,15 +1000,16 @@ If we want the result of matching, use:} {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} +\Algorithm{Fenwick Tree} +{} +{} +{cpp} {source/DS/Fenwick.cpp} \Algorithm{Segment Tree} @@ -1004,11 +1024,11 @@ If we want the result of matching, use:} % {cpp} % {source/DS/SegmentTree.cpp} -\Algorithm{Segment Tree Beats} -{} -{$\mathcal O(\log N)$ on updating and querying} -{cpp} -{source/DS/STBeats.cpp} +% \Algorithm{Segment Tree Beats} +% {} +% {$\mathcal O(\log N)$ on updating and querying} +% {cpp} +% {source/DS/STBeats.cpp} \Algorithm{Li-Chao Tree} {} @@ -1023,7 +1043,7 @@ If we want the result of matching, use:} {source/DS/SplayTree.cpp} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Numerical Analysis} +% \section{Numerical Analysis} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1043,8 +1063,6 @@ If we want the result of matching, use:} {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);}.} {} diff --git a/source/DS/Fenwick.cpp b/source/DS/Fenwick.cpp index 42bd6ef..a80d122 100644 --- a/source/DS/Fenwick.cpp +++ b/source/DS/Fenwick.cpp @@ -1,9 +1,7 @@ ll tree[N]; -void update(int i,ll x) { - while(i < N) tree[i] += x, i += i&-i; -} +void update(int i,ll x){ while(i +// https://codeforces.com/blog/entry/11080 #include #include #include @@ -8,30 +8,17 @@ using namespace __gnu_cxx; template using indexed_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -indexed_set s; -s.insert(3); s.insert(2); s.insert(3); s.insert(9); s.insert(7); //2 3 7 9 -s.insert(5); //2 3 5 7 9 -s.erase(5); //2 3 7 9 +// indexed_set s; +// s.insert(3); s.insert(2); s.insert(3); s.insert(9); s.insert(7); //2 3 7 9 +// s.insert(5); //2 3 5 7 9 +// s.erase(5); //2 3 7 9 -auto x = s.find_by_order(2); // *x : 7 +// auto x = s.find_by_order(2); // *x : 7 +// s.order_of_key(6) // 2 +// s.order_of_key(7) // 2 +// s.order_of_key(8) // 3 +// indexed_multiset: use {key, unique} as key -s.order_of_key(6) // 2 -s.order_of_key(7) // 2 -s.order_of_key(8) // 3 - -///////////////////////////////////////////////////////////// -// greater_equal <- ordered_multiset / greater <- ordered_multiset -#define oset_greater tree, rb_tree_tag, tree_order_statistics_node_update> -#define oset_less tree, rb_tree_tag, tree_order_statistics_node_update> - -void oset_m_erase(ordered_set_greater &OS, ll val){ - int index = OS.order_of_key(val); - oset_greater::iterator it = OS.find_by_order(index); - if(it != OS.end() && *it == val) OS.erase(it); -} - - -///////////////////////////////////////////////////////////// -rope r; -r.insert(r.size() - t, i); //r.size()-t번째 자리에 i를 삽입 -r.substr(a, b - a + 1) // a부터 (b-a+1)개 만큼을 잘라낸다. 즉, [a, b] 선택 +// rope r; +// r.insert(r.size() - t, i); //r.size()-t번째 자리에 i를 삽입 +// r.substr(a, b - a + 1) // a부터 (b-a+1)개 만큼을 잘라낸다. 즉, [a, b] 선택 diff --git a/source/DS/SplayTree.cpp b/source/DS/SplayTree.cpp index dc46b95..0b76cd3 100644 --- a/source/DS/SplayTree.cpp +++ b/source/DS/SplayTree.cpp @@ -20,7 +20,7 @@ val += lazy; sum += cnt * lazy; if(l) l->lazy += lazy; if(r) r->lazy += lazy; la } *root; -// 자기보다 더 높은 노드를 루트로 하는 SplayTree를 조작하는 경우, 하위 SplayTree는 unvalid된다. +// 자기보다 더 높은 노드를 루트로 하는 SplayTree를 조작하는 경우, 하위 SplayTree는 invalid. struct SplayTree{ Node *root = NULL, *rp = NULL; SplayTree(){} diff --git a/source/Graph/Matching.cpp b/source/Graph/Matching.cpp index 22eb9a6..61a9810 100644 --- a/source/Graph/Matching.cpp +++ b/source/Graph/Matching.cpp @@ -1,18 +1,15 @@ -// From https://github.com/koosaga/olympiad -// matching_short.cpp -const int MAXN = 2020 + 1; -// 1-based Vertex index -int vis[MAXN], par[MAXN], orig[MAXN], match[MAXN], aux[MAXN], t, N; -vector conn[MAXN]; -queue Q; +// Originate from https://github.com/koosaga/olympiad +// matching_short.cpp / 1-based Vertex index / const int N = 2020 + 1; +int vis[N], par[N], orig[N], match[N], aux[N], t, n; +vector conn[N]; queue Q; + void addEdge(int u, int v) { conn[u].push_back(v); conn[v].push_back(u); } void init(int n) { - N = n; t = 0; - for(int i=0; i<=n; ++i) { - conn[i].clear(); - match[i] = aux[i] = par[i] = 0; - } + ::n = n; t = 0; + fors(i, 0, n) conn[i].clear(); + fors(i, 0, n) match[i] = aux[i] = par[i] = 0; } + void augment(int u, int v) { int pv = v, nv; do { @@ -35,12 +32,11 @@ void blossom(int v, int w, int a) { while(orig[v] != a) { par[v] = w; w = match[v]; if(vis[w] == 1) Q.push(w), vis[w] = 0; - orig[v] = orig[w] = a; - v = par[w]; + orig[v] = orig[w] = a; v = par[w]; } } bool bfs(int u) { - fill(vis+1, vis+1+N, -1); iota(orig + 1, orig + N + 1, 1); + fill(vis+1, vis+1+n, -1); iota(orig + 1, orig + n + 1, 1); Q = queue (); Q.push(u); vis[u] = 0; while(!Q.empty()) { int v = Q.front(); Q.pop(); @@ -58,17 +54,15 @@ bool bfs(int u) { } return false; } -int Match() { +int matching() { int ans = 0; // find random matching (not necessary, constant improvement) - vector V(N-1); iota(V.begin(), V.end(), 1); + vector V(n-1); iota(V.begin(), V.end(), 1); shuffle(V.begin(), V.end(), mt19937(0x94949)); - for(auto x: V) if(!match[x]){ - for(auto y: conn[x]) if(!match[y]) { - match[x] = y, match[y] = x; - ++ans; break; - } + for(auto x: V) if(!match[x]) for(auto y: conn[x]) if(!match[y]) { + match[x] = y, match[y] = x; + ++ans; break; } - for(int i=1; i<=N; ++i) if(!match[i] && bfs(i)) ++ans; + forr(i, n) if(!match[i] && bfs(i)) ++ans; return ans; } \ No newline at end of file diff --git a/source/Math/NTT.cpp b/source/Math/NTT.cpp index 836403e..9269b50 100644 --- a/source/Math/NTT.cpp +++ b/source/Math/NTT.cpp @@ -1,32 +1,26 @@ namespace GMS { template ll pow(ll a, ll b) { - a %= mod; - ll ret = 1; + ll ret = 1; a %= mod; while(b != 0) { if(b&1) ret = ret*a%mod; - a = a*a%mod; b>>=1; + a = a*a%mod, b/=2; } return ret; } template -void ntt(vector &a, bool inv = false) { +void ntt(vl& a, bool inv = false) { static_assert(mod <= (ll)2e9, "mod should be less than 2e9"); int n = a.size(), j = 0; - assert((n & -n) == n && (mod-1)%n == 0); for(int i=1; i> 1); - while(j >= bit) { - j -= bit; - bit >>= 1; - } - j += bit; - if(i < j) swap(a[i], a[j]); + int bit = n/2; + while(j >= bit) {j -= bit; bit >>= 1;} + j += bit; if(i < j) swap(a[i], a[j]); } - static vector root[30], iroot[30]; + static vl root[30], iroot[30]; for(int st=1; (1<(w, (mod-1)/(1< &a, bool inv = false) { } vector* r = (inv?root:iroot); - for(int st = 1; (1<(A); ntt(B); - fors(i, 0, t-1) A[i] = A[i]*B[i]%mod; - ntt(A, true); - A.resize(n+m-1); - return A; + return A.resize(n+m-1), A; } } // namespace GMS \ No newline at end of file diff --git a/source/Math/Polynomial.cpp b/source/Math/Polynomial.cpp index 2111d1f..f2867be 100644 --- a/source/Math/Polynomial.cpp +++ b/source/Math/Polynomial.cpp @@ -51,7 +51,7 @@ struct Qring : public vl { } friend poly operator*(const poly& A, const poly& B) { poly ret = conv(A, B); - // ACL : poly ret = atcoder::convolution(A, B); + // poly ret = atcoder::convolution(A, B); // ACL return ret.adjust(), ret; } friend poly inv(const poly& A, int t) { assert(A[0] != 0); @@ -89,16 +89,15 @@ struct Qring : public vl { ll idx = 0; while(ret[idx] == 0) idx++; if((__int128_t) idx * b >= t) return poly(0, t); - ll c = ret[idx]; ll ic = pow(ret[idx], mod-2); poly g; - int n = ret.size(); + ll c = ret[idx]; ll ic = pow(ret[idx], mod-2); + poly g; int n = ret.size(); fors(i, idx, n-1) g[i-idx] = ret[i]*ic%mod; g.resize(t-idx*b); - g = exp(b * log(g, t-idx*b), t-idx*b); c = pow(c, b); - ret = poly(0, t); fors(i, idx*b, t-1) ret[i] = g[i-idx*b] * c % mod; - + ret = poly(0, t); + fors(i, idx*b, t-1) ret[i] = g[i-idx*b] * c % mod; return ret; } diff --git a/source/Math/PrimitiveRoot.cpp b/source/Math/PrimitiveRoot.cpp index 09b1621..9497119 100644 --- a/source/Math/PrimitiveRoot.cpp +++ b/source/Math/PrimitiveRoot.cpp @@ -1,16 +1,14 @@ +random_device rd; mt19937 rng(rd()); + ll primary_root(ll p) { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution distrib(1, p-1); - - //distrib(gen); + uniform_int_distribution dist(1, p-1); + auto gen = bind(dist, rng); + vl g = po_rho(p-1); - while(true) { - ll c = distrib(gen); - - bool ok = true; ll u = p-1; - ll b = 1; + ll c = gen(), u = p-1, b = 1; + bool ok = true; + for(auto i:g) { if(i != b) u = p-1; ll x = pow(c, u/i, p); diff --git a/source/Math/math.tex b/source/Math/math.tex index e222983..c729e67 100644 --- a/source/Math/math.tex +++ b/source/Math/math.tex @@ -33,64 +33,154 @@ If $a_n = c_1 a_{n-1} + \dots + c_k a_{n-k}$, and $r_1, \dots, r_k$ are distinct \[a_n = d_1r_1^n + \dots + d_kr_k^n. \] Non-distinct roots $r$ become polynomial factors, e.g. $a_n = (d_1n + d_2)r^n$. -% \subsection{Trigonometry} -% \begin{align*} -% \sin(v+w)&{}=\sin v\cos w+\cos v\sin w\\ -% \cos(v+w)&{}=\cos v\cos w-\sin v\sin w\\ -% \tan(v+w)&{}=\dfrac{\tan v+\tan w}{1-\tan v\tan w}\\ -% \sin v+\sin w&{}=2\sin\dfrac{v+w}{2}\cos\dfrac{v-w}{2}\\ -% \cos v+\cos w&{}=2\cos\dfrac{v+w}{2}\cos\dfrac{v-w}{2}\\ -% (V+W)\tan(v-w)/2&{}=(V-W)\tan(v+w)/2 -% \end{align*} -% where $V, W$ are lengths of sides opposite angles $v, w$. -% \begin{align*} -% a\cos x+b\sin x&=r\cos(x-\phi)\\ -% a\sin x+b\cos x&=r\sin(x+\phi) -% \end{align*} -% where $r=\sqrt{a^2+b^2}, \phi=\operatorname{atan2}(b,a)$. +\subsection{Trigonometry} +\begin{align*} +\sin(v+w)&{}=\sin v\cos w+\cos v\sin w\\ +\cos(v+w)&{}=\cos v\cos w-\sin v\sin w\\ +\tan(v+w)&{}=\dfrac{\tan v+\tan w}{1-\tan v\tan w}\\ +\sin v+\sin w&{}=2\sin\dfrac{v+w}{2}\cos\dfrac{v-w}{2}\\ +\cos v+\cos w&{}=2\cos\dfrac{v+w}{2}\cos\dfrac{v-w}{2}\\ +(V+W)\tan(v-w)/2&{}=(V-W)\tan(v+w)/2 +\end{align*} +where $V, W$ are lengths of sides opposite angles $v, w$. +\begin{align*} + a\cos x+b\sin x&=r\cos(x-\phi)\\ + a\sin x+b\cos x&=r\sin(x+\phi) +\end{align*} +where $r=\sqrt{a^2+b^2}, \phi=\operatorname{atan2}(b,a)$. \subsection{Geometry} +\subsubsection{Spherical coordinates} +\begin{center} +\includegraphics[width=25mm]{source/Math/sphericalCoordinates.pdf} +\end{center} +\[\begin{array}{cc} +x = r\sin\theta\cos\phi & r = \sqrt{x^2+y^2+z^2}\\ +y = r\sin\theta\sin\phi & \theta = \textrm{acos}(z/\sqrt{x^2+y^2+z^2})\\ +z = r\cos\theta & \phi = \textrm{atan2}(y,x) +\end{array}\] + \subsubsection{Triangles} -Side lengths: $a,b,c$ -Semiperimeter: $p=\dfrac{a+b+c}{2}$ +\begin{tikzpicture}[scale=1.1] -Area: $A=\sqrt{p(p-a)(p-b)(p-c)}$ +%------------------------------------------------ +% Triangle +%------------------------------------------------ +\tkzDefPoint(0,0){B} +\tkzDefPoint(6,0){C} +\tkzDefPoint(2,4.5){A} -Circumradius: $R=\dfrac{abc}{4A}$ -Inradius: $r=\dfrac{A}{p}$ +\tkzDrawPolygon[thick](A,B,C) -Length of the median (divides the triangle into two equal area triangles): $m_a=\tfrac{1}{2}\sqrt{2b^2+2c^2-a^2}$ +%------------------------------------------------ +% Midpoint & Median +%------------------------------------------------ +\tkzDefMidPoint(B,C) +\tkzGetPoint{M} -Length of the bisector (divides angles into two): $s_a=\sqrt{bc\left[1-\left(\dfrac{a}{b+c}\right)^2\right]}$ +\tkzDrawSegment[dashed](A,M) +\tkzLabelSegment[right](A,M){$m_a$} +\tkzMarkSegments[mark=||, size=3pt, color=blue](B,M M,C) -Law of sines: $\dfrac{\sin\alpha}{a}=\dfrac{\sin\beta}{b}=\dfrac{\sin\gamma}{c}=\dfrac{1}{2R}$ -Law of cosines: $a^2=b^2+c^2-2bc\cos\alpha$ +%------------------------------------------------ +% Angle bisector +%------------------------------------------------ +\tkzDefLine[bisector](B,A,C) +\tkzGetPoint{X} +\tkzInterLL(A,X)(B,C) +\tkzGetPoint{S} -Law of tangents: $\dfrac{a+b}{a-b}=\dfrac{\tan\dfrac{\alpha+\beta}{2}}{\tan\dfrac{\alpha-\beta}{2}}$ +\tkzDrawSegment[densely dotted](A,S) +\tkzLabelSegment[left](A,S){$s_a$} + +%------------------------------------------------ +% Incenter & Incircle +%------------------------------------------------ +\tkzInCenter(A,B,C) +\tkzGetPoint{I} +\tkzDrawPoint[fill=black](I) + +\tkzDefPointBy[projection=onto B--C](I) +\tkzGetPoint{H_a} + + +\tkzDrawCircle[thick, red](I, H_a) + +\tkzDrawSegment[->](I,H_a) +\tkzLabelSegment[left](I,H_a){$r$} + +%------------------------------------------------ +% Circumcenter & Circumcircle +%------------------------------------------------ +\tkzCircumCenter(A,B,C) +\tkzGetPoint{O} + +\tkzDrawCircle[thick, blue](O,A) + +\tkzDrawSegment(O,C) +\tkzLabelSegment[above](O,C){$R$} + +%------------------------------------------------ +% Labels +%------------------------------------------------ +\tkzLabelPoints[above](A) +\tkzLabelPoints[left](B) +\tkzLabelPoints[right](C) +\tkzLabelPoints[left](I) +\tkzLabelPoints[above](O) +\tkzLabelPoints[below](H_a) +\tkzLabelPoints[below](M) + +\tkzDrawPoint[fill=black](A) +\tkzDrawPoint[fill=black](B) +\tkzDrawPoint[fill=black](C) +\tkzDrawPoint[fill=black](O) +\tkzDrawPoint[fill=black](H_a) +\tkzDrawPoint[fill=black](M) + + +\tkzLabelSegment[left=0.7](A,B){$c$} +\tkzLabelSegment[above right=0.7](A,C){$b$} +\tkzLabelSegment[below=0.7](B,C){$a$} + +\draw[dashed] (A) to[bend right=17] (B); +\draw[dashed] (B) to[bend right=17] (C); +\draw[dashed] (C) to[bend right=17] (A); + +% \node at (2.7,1.7) {$A$}; + +\end{tikzpicture} + + +Semiperimeter $s = \dfrac{a+b+c}{2}$; Area $A=\sqrt{s(s-a)(s-b)(s-c)}$ + +% Circumradius: +% Inradius: +% Length of the median (divides the triangle into two equal area triangles): +$R=\dfrac{abc}{4A}$; $r=\dfrac{A}{s}$; $m_a=\tfrac{1}{2}\sqrt{2b^2+2c^2-a^2}$ + + +% Length of the bisector (divides angles into two): +$s_a=\sqrt{bc\left[1-\left(\dfrac{a}{b+c}\right)^2\right]}$ + +$2R=\dfrac{a}{\sin A}=\dfrac{b}{\sin B}=\dfrac{c}{\sin C}$ + +$a=b\cos C+c\cos B$; $a^2=b^2+c^2-2bc\cos A$; $\dfrac{a+b}{a-b}=\dfrac{\tan\dfrac{\alpha+\beta}{2}}{\tan\dfrac{\alpha-\beta}{2}}$ \subsubsection{Quadrilaterals} With side lengths $a,b,c,d$, diagonals $e, f$, diagonals angle $\theta$, area $A$ and magic flux $F=b^2+d^2-a^2-c^2$: -\[ 4A = 2ef \cdot \sin\theta = F\tan\theta = \sqrt{4e^2f^2-F^2} \] +\[ 4A = 2ef \sin\theta = F\tan\theta = \sqrt{4e^2f^2-F^2} \] For cyclic quadrilaterals the sum of opposite angles is $180^\circ$, $ef = ac + bd$, and $A = \sqrt{(p-a)(p-b)(p-c)(p-d)}$. -% \subsubsection{Spherical coordinates} -% \begin{center} -% \includegraphics[width=25mm]{source/Math/sphericalCoordinates.pdf} -% \end{center} -% \[\begin{array}{cc} -% x = r\sin\theta\cos\phi & r = \sqrt{x^2+y^2+z^2}\\ -% y = r\sin\theta\sin\phi & \theta = \textrm{acos}(z/\sqrt{x^2+y^2+z^2})\\ -% z = r\cos\theta & \phi = \textrm{atan2}(y,x) -% \end{array}\] \subsection{Derivatives/Integrals} \begin{align*} diff --git a/source/Misc/NegDiv.cpp b/source/Misc/NegDiv.cpp index e0bbf90..17f83fe 100644 --- a/source/Misc/NegDiv.cpp +++ b/source/Misc/NegDiv.cpp @@ -1,7 +1,5 @@ #define div _div -ll div(ll A, ll B) -{ - ll q = A/B; - if(A<0) q-=(B>0)-(B<0); +ll div(ll A, ll B) { + ll q = A/B; if(A<0) q-=(B>0)-(B<0); return q; } \ No newline at end of file diff --git a/source/Misc/mt19937.cpp b/source/Misc/mt19937.cpp index 0be15b7..393125b 100644 --- a/source/Misc/mt19937.cpp +++ b/source/Misc/mt19937.cpp @@ -1,7 +1,18 @@ -const long long rand_L = 1; -const long long rand_R = 10; -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); -uniform_int_distribution dist(rand_L, rand_R); +const long long L = 1, R = 10; + +random_device rd; mt19937 rng(rd()); +uniform_int_distribution dist(L, R); +// discrete_distribution dist({10, 30, 60}); // [0, 2] +// bernoulli_distribution dist(p); // true(p), false(1-p) +// binomial_distribution dist(N, p); // # of success +// geometric_distribution dist(p); // # of failure + +// uniform_real_distribution dist(L, R); +// normal_distribution dist(mean, std); +// exponential_distribution dist(lambda); // occur time +// poisson_distribution dist(lambda); // how many? +// chi_squared_distribution dist(df); // 자유도 + auto gen = bind(dist, rng); gen(); gen(); gen(); \ No newline at end of file diff --git a/source/String/Duval.cpp b/source/String/Duval.cpp new file mode 100644 index 0000000..845289f --- /dev/null +++ b/source/String/Duval.cpp @@ -0,0 +1,12 @@ +// https://koosaga.com/301 +vi duval(vi &s){ + int n=s.size(), i=0; vi v; + while(i sz[adj[s][0]]) swap(adj[s][0], i); } @@ -27,14 +29,14 @@ int query(int a,int b) { int ans = 0; while(top[a] != top[b]) { if(d[top[a]] > d[top[b]]) swap(a, b); - ans = max(ans, query(root, in[top[b]], in[b])); + ans = max(ans, query(seg, in[top[b]], in[b])); b = par[top[b]]; } if(d[a] > d[b]) swap(a, b); - return max(ans, query(root, in[a]+1, in[b])); + return max(ans, query(seg, in[a]+1, in[b])); } // dfs1(1); dfs2(1); -// forr(i, n) arr[in[i]] = m[{par[i], i}]; init(root, arr); -// q == 1: update(root, in[a], c); // in[a]를 c로 대체 +// forr(i, n) arr[in[i]] = m[{par[i], i}]; init(seg, arr); +// q == 1: update(seg, in[a], c); // in[a]를 c로 대체 // q == 2: query(a, b); \ No newline at end of file diff --git a/source/cy4n1de.cpp b/source/cy4n1de.cpp new file mode 100644 index 0000000..0173f63 --- /dev/null +++ b/source/cy4n1de.cpp @@ -0,0 +1,38 @@ +#include +#ifdef LOCAL +#define dbg(x) cerr << #x << " = " << (x) << endl +#else +#define dbg(x) +#endif + +using ll=long long; +#define pii pair +#define vi vector +#define vll vector +#define all(v) v.begin(), v.end() +#define cyan cin.tie(0)->sync_with_stdio(0); +/* +auto max_it = max_element(all(v)) +// Find the first element strictly greater than k +auto it = upper_bound(all(v), k); +// Find the first element geq than k +auto it = lower_bound(all(v), 30); +*/ +//compress- 중복제거해서 정렬 +#define compress(vec) do { \ + sort((vec).begin(), (vec).end()); \ + (vec).erase(unique((vec).begin(), (vec).end()), (vec).end()); \ +} while(0) + +#define elif else if +#define endl '\n' +using namespace std; +const ll MOD = 1e9+7; +ll modpow(ll a, ll b, ll m=MOD){ // a^b mod m + ll r=1; a%=m; + for(; b; b>>=1, a=a*a%m) if(b&1) r=r*a%m; + return r; +} +int main(){ + cyan +} diff --git a/source/poro.sh b/source/poro.sh index cf77aec..f0754d4 100644 --- a/source/poro.sh +++ b/source/poro.sh @@ -1,3 +1,3 @@ mkdir {A..M} -alias solve='g++ main.cpp -o solve_exefile -g -fsanitize=undefined,address -fno-omit-frame-pointer -Wall -Wextra && echo "Compile Done" && time ./solve_exefile' -alias fast='g++ main.cpp -o solve_exefile -O2 -Wall && echo "Compile Done" && time ./solve_exefile' +alias solve='g++ main.cpp -o main -g -fsanitize=undefined,address -fno-omit-frame-pointer -Wall -Wextra && echo "Compile Done" && time ./main' +alias fast='g++ main.cpp -o main -O2 -Wall && echo "Compile Done" && time ./main'