update ucpc2026

This commit is contained in:
2026-07-11 09:38:32 +09:00
parent 7176febe54
commit 0b8c2864ae
20 changed files with 329 additions and 163 deletions
+2
View File
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-include, /home/remote/teamnote/lib/default.cpp, --std=c++23]
+6 -1
View File
@@ -13,5 +13,10 @@
"%DOC%" "%DOC%"
], ],
"env": {} "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,
} }
+24
View File
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>
#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<int,int>; using pll = pair<ll,ll>;
using vi = vector<int>; using vl = vector<ll>;
using vii = vector<pii>; using vll = vector<pll>;
const int N = 2e5+7, inf=1e9+7;
BIN
View File
Binary file not shown.
+37 -19
View File
@@ -11,6 +11,10 @@
\usepackage{subfiles} \usepackage{subfiles}
\usepackage{amsmath} \usepackage{amsmath}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usepackage{etoolbox} \usepackage{etoolbox}
\AtBeginEnvironment{align*}{% \AtBeginEnvironment{align*}{%
@@ -38,7 +42,7 @@
\usepackage{multicol} \usepackage{multicol}
\setlength\columnseprule{0.5pt} \setlength\columnseprule{0.5pt}
\teamnote{POSTECH}{ConSpirito}{}{ICPC Seoul Regional} \teamnote{UCPC 2025 Final}{아팀명모하지}{아팀명모하지}{}
\ShowUsage \ShowUsage
\ShowComplexity \ShowComplexity
@@ -72,6 +76,7 @@
\item calculating error bound on a real number usage? \item calculating error bound on a real number usage?
\end{itemize} \end{itemize}
\subsection{checked...} \subsection{checked...}
\begin{itemize} \begin{itemize}
@@ -378,11 +383,16 @@ When you don't have any ideas, please bruteforce it.
\end{tcolorbox} \end{tcolorbox}
\Algorithm{POROGOD}{}{}{bash}{source/poro.cpp} \Algorithm{POROGOD}{}{}{bash}{source/poro.sh}
\pagebreak % \pagebreak
% \Algorithm{astilate}{}{}{cpp}{source/Fundemental.cpp} % \Algorithm{astilate}{}{}{cpp}{source/Fundemental.cpp}
\Algorithm{cy4n1de}{}{}{cpp}{source/cy4n1de.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Math}
\subsection{Tips for Inequality with Rational Number} \subsection{Tips for Inequality with Rational Number}
Let $A$, $B$, $x$, $n$ be integer, and operator `/' means floor division(quotient). 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 \\ \\ Ax > B & \Leftrightarrow x \geqslant B/A+1 \\ \\
x < n & \Leftrightarrow x+1\leqslant n x < n & \Leftrightarrow x+1\leqslant n
\end{align*} \end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Math}
\subfile{source/Math/math} \subfile{source/Math/math}
\subsection{Prime Number} \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} \Algorithm{NTT - Number Theoretic Transform}
{helloworld} {}
{} {}
{cpp} {cpp}
{source/Math/NTT.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} \section{DP}
\Algorithm{LIS} % \Algorithm{LIS}
{}{}{cpp}{source/DP/LIS.cpp} % {}{}{cpp}{source/DP/LIS.cpp}
\subsection{DP Optimization} \subsection{DP Optimization}
@@ -871,6 +879,17 @@ D_{min}(p) &= \min_i|A_i-B_{p_i}| && \text{ maximize } D_{min} &&& \Rightarrow p
{cpp} {cpp}
{source/String/AhoCorasick.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} \Algorithm{Eertree}
{} {}
{} {}
@@ -981,15 +1000,16 @@ If we want the result of matching, use:}
{cpp} {cpp}
{source/DS/PBDS.cpp} {source/DS/PBDS.cpp}
% \Algorithm{rope}{}{}{cpp}{}
\Algorithm{Union and Find - Queue Undoing} \Algorithm{Union and Find - Queue Undoing}
{} {}
{$\mathcal O(\log^2N)$} {$\mathcal O(\log^2N)$}
{cpp} {cpp}
{source/DS/UF_QUndo.cpp} {source/DS/UF_QUndo.cpp}
\Algorithm{Fenwick Tree}{}{}{cpp} \Algorithm{Fenwick Tree}
{}
{}
{cpp}
{source/DS/Fenwick.cpp} {source/DS/Fenwick.cpp}
\Algorithm{Segment Tree} \Algorithm{Segment Tree}
@@ -1004,11 +1024,11 @@ If we want the result of matching, use:}
% {cpp} % {cpp}
% {source/DS/SegmentTree.cpp} % {source/DS/SegmentTree.cpp}
\Algorithm{Segment Tree Beats} % \Algorithm{Segment Tree Beats}
{} % {}
{$\mathcal O(\log N)$ on updating and querying} % {$\mathcal O(\log N)$ on updating and querying}
{cpp} % {cpp}
{source/DS/STBeats.cpp} % {source/DS/STBeats.cpp}
\Algorithm{Li-Chao Tree} \Algorithm{Li-Chao Tree}
{} {}
@@ -1023,7 +1043,7 @@ If we want the result of matching, use:}
{source/DS/SplayTree.cpp} {source/DS/SplayTree.cpp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Numerical Analysis} % \section{Numerical Analysis}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1043,8 +1063,6 @@ If we want the result of matching, use:}
{cpp} {cpp}
{source/Misc/NegDiv.cpp} {source/Misc/NegDiv.cpp}
\Algorithm{Fast Input} \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);}.} {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);}.}
{} {}
+2 -4
View File
@@ -1,9 +1,7 @@
ll tree[N]; ll tree[N];
void update(int i,ll x) { void update(int i,ll x){ while(i<N) tree[i] += x, i+=i&-i; }
while(i < N) tree[i] += x, i += i&-i;
}
int query(int i) { int query(int i) {
ll s = 0; ll s = 0;
while(i) s += tree[i], i -= i&-i; while(i) s += tree[i], i-=i&-i;
return s; return s;
} }
+13 -26
View File
@@ -1,4 +1,4 @@
#include <bits/stdc++.h> // https://codeforces.com/blog/entry/11080
#include <ext/rope> #include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/tree_policy.hpp>
@@ -8,30 +8,17 @@ using namespace __gnu_cxx;
template<typename T> template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
indexed_set<int> s; // indexed_set<int> s;
s.insert(3); s.insert(2); s.insert(3); s.insert(9); s.insert(7); //2 3 7 9 // 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.insert(5); //2 3 5 7 9
s.erase(5); //2 3 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 // rope<ll> r;
s.order_of_key(7) // 2 // r.insert(r.size() - t, i); //r.size()-t번째 자리에 i를 삽입
s.order_of_key(8) // 3 // r.substr(a, b - a + 1) // a부터 (b-a+1)개 만큼을 잘라낸다. 즉, [a, b] 선택
/////////////////////////////////////////////////////////////
// greater_equal <- ordered_multiset / greater <- ordered_multiset
#define oset_greater tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define oset_less tree<ll, null_type, less_equal<ll>, 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<ll> r;
r.insert(r.size() - t, i); //r.size()-t번째 자리에 i를 삽입
r.substr(a, b - a + 1) // a부터 (b-a+1)개 만큼을 잘라낸다. 즉, [a, b] 선택
+1 -1
View File
@@ -20,7 +20,7 @@ val += lazy; sum += cnt * lazy; if(l) l->lazy += lazy; if(r) r->lazy += lazy; la
} *root; } *root;
// 자기보다 더 높은 노드를 루트로 하는 SplayTree를 조작하는 경우, 하위 SplayTree는 unvalid된다. // 자기보다 더 높은 노드를 루트로 하는 SplayTree를 조작하는 경우, 하위 SplayTree는 invalid.
struct SplayTree{ struct SplayTree{
Node *root = NULL, *rp = NULL; Node *root = NULL, *rp = NULL;
SplayTree(){} SplayTree(){}
+15 -21
View File
@@ -1,18 +1,15 @@
// From https://github.com/koosaga/olympiad // Originate from https://github.com/koosaga/olympiad
// matching_short.cpp // matching_short.cpp / 1-based Vertex index / const int N = 2020 + 1;
const int MAXN = 2020 + 1; int vis[N], par[N], orig[N], match[N], aux[N], t, n;
// 1-based Vertex index vector<int> conn[N]; queue<int> Q;
int vis[MAXN], par[MAXN], orig[MAXN], match[MAXN], aux[MAXN], t, N;
vector<int> conn[MAXN];
queue<int> Q;
void addEdge(int u, int v) { conn[u].push_back(v); conn[v].push_back(u); } void addEdge(int u, int v) { conn[u].push_back(v); conn[v].push_back(u); }
void init(int n) { void init(int n) {
N = n; t = 0; ::n = n; t = 0;
for(int i=0; i<=n; ++i) { fors(i, 0, n) conn[i].clear();
conn[i].clear(); fors(i, 0, n) match[i] = aux[i] = par[i] = 0;
match[i] = aux[i] = par[i] = 0;
}
} }
void augment(int u, int v) { void augment(int u, int v) {
int pv = v, nv; int pv = v, nv;
do { do {
@@ -35,12 +32,11 @@ void blossom(int v, int w, int a) {
while(orig[v] != a) { while(orig[v] != a) {
par[v] = w; w = match[v]; par[v] = w; w = match[v];
if(vis[w] == 1) Q.push(w), vis[w] = 0; if(vis[w] == 1) Q.push(w), vis[w] = 0;
orig[v] = orig[w] = a; orig[v] = orig[w] = a; v = par[w];
v = par[w];
} }
} }
bool bfs(int u) { 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<int> (); Q.push(u); vis[u] = 0; Q = queue<int> (); Q.push(u); vis[u] = 0;
while(!Q.empty()) { while(!Q.empty()) {
int v = Q.front(); Q.pop(); int v = Q.front(); Q.pop();
@@ -58,17 +54,15 @@ bool bfs(int u) {
} }
return false; return false;
} }
int Match() { int matching() {
int ans = 0; int ans = 0;
// find random matching (not necessary, constant improvement) // find random matching (not necessary, constant improvement)
vector<int> V(N-1); iota(V.begin(), V.end(), 1); vector<int> V(n-1); iota(V.begin(), V.end(), 1);
shuffle(V.begin(), V.end(), mt19937(0x94949)); shuffle(V.begin(), V.end(), mt19937(0x94949));
for(auto x: V) if(!match[x]){ for(auto x: V) if(!match[x]) for(auto y: conn[x]) if(!match[y]) {
for(auto y: conn[x]) if(!match[y]) {
match[x] = y, match[y] = x; match[x] = y, match[y] = x;
++ans; break; ++ans; break;
} }
} forr(i, n) if(!match[i] && bfs(i)) ++ans;
for(int i=1; i<=N; ++i) if(!match[i] && bfs(i)) ++ans;
return ans; return ans;
} }
+8 -18
View File
@@ -1,32 +1,26 @@
namespace GMS { namespace GMS {
template<ll mod> template<ll mod>
ll pow(ll a, ll b) { ll pow(ll a, ll b) {
a %= mod; ll ret = 1; a %= mod;
ll ret = 1;
while(b != 0) { while(b != 0) {
if(b&1) ret = ret*a%mod; if(b&1) ret = ret*a%mod;
a = a*a%mod; b>>=1; a = a*a%mod, b/=2;
} }
return ret; return ret;
} }
template<ll mod, ll w> template<ll mod, ll w>
void ntt(vector<ll> &a, bool inv = false) { void ntt(vl& a, bool inv = false) {
static_assert(mod <= (ll)2e9, "mod should be less than 2e9"); static_assert(mod <= (ll)2e9, "mod should be less than 2e9");
int n = a.size(), j = 0; int n = a.size(), j = 0;
assert((n & -n) == n && (mod-1)%n == 0); assert((n & -n) == n && (mod-1)%n == 0);
for(int i=1; i<n; i++) { for(int i=1; i<n; i++) {
int bit = (n >> 1); int bit = n/2;
while(j >= bit) { while(j >= bit) {j -= bit; bit >>= 1;}
j -= bit; j += bit; if(i < j) swap(a[i], a[j]);
bit >>= 1;
}
j += bit;
if(i < j) swap(a[i], a[j]);
} }
static vector<ll> root[30], iroot[30]; static vl root[30], iroot[30];
for(int st=1; (1<<st) <= n; st++) { for(int st=1; (1<<st) <= n; st++) {
if(root[st].empty()) { if(root[st].empty()) {
ll t = pow<mod>(w, (mod-1)/(1<<st)); ll t = pow<mod>(w, (mod-1)/(1<<st));
@@ -46,7 +40,6 @@ void ntt(vector<ll> &a, bool inv = false) {
} }
vector<ll>* r = (inv?root:iroot); vector<ll>* r = (inv?root:iroot);
for(int st = 1; (1<<st) <= n; st++) { for(int st = 1; (1<<st) <= n; st++) {
int i = 1<<st; //int step = n / i; int i = 1<<st; //int step = n / i;
for(int j=0; j<n; j+=i) { for(int j=0; j<n; j+=i) {
@@ -70,12 +63,9 @@ vl conv(vl A, vl B) {
A.resize(t); B.resize(t); A.resize(t); B.resize(t);
ntt<mod, w>(A); ntt<mod, w>(B); ntt<mod, w>(A); ntt<mod, w>(B);
fors(i, 0, t-1) A[i] = A[i]*B[i]%mod; fors(i, 0, t-1) A[i] = A[i]*B[i]%mod;
ntt<mod, w>(A, true); ntt<mod, w>(A, true);
A.resize(n+m-1);
return A; return A.resize(n+m-1), A;
} }
} // namespace GMS } // namespace GMS
+5 -6
View File
@@ -51,7 +51,7 @@ struct Qring : public vl {
} }
friend poly operator*(const poly& A, const poly& B) { friend poly operator*(const poly& A, const poly& B) {
poly ret = conv<mod, w>(A, B); poly ret = conv<mod, w>(A, B);
// ACL : poly ret = atcoder::convolution<mod>(A, B); // poly ret = atcoder::convolution<mod>(A, B); // ACL
return ret.adjust(), ret; return ret.adjust(), ret;
} }
friend poly inv(const poly& A, int t) { assert(A[0] != 0); 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++; ll idx = 0; while(ret[idx] == 0) idx++;
if((__int128_t) idx * b >= t) return poly(0, t); if((__int128_t) idx * b >= t) return poly(0, t);
ll c = ret[idx]; ll ic = pow<mod>(ret[idx], mod-2); poly g; ll c = ret[idx]; ll ic = pow<mod>(ret[idx], mod-2);
int n = ret.size(); poly g; int n = ret.size();
fors(i, idx, n-1) g[i-idx] = ret[i]*ic%mod; fors(i, idx, n-1) g[i-idx] = ret[i]*ic%mod;
g.resize(t-idx*b); g.resize(t-idx*b);
g = exp(b * log(g, t-idx*b), t-idx*b); g = exp(b * log(g, t-idx*b), t-idx*b);
c = pow<mod>(c, b); c = pow<mod>(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; return ret;
} }
+6 -8
View File
@@ -1,16 +1,14 @@
random_device rd; mt19937 rng(rd());
ll primary_root(ll p) { ll primary_root(ll p) {
std::random_device rd; uniform_int_distribution<ll> dist(1, p-1);
std::mt19937 gen(rd()); auto gen = bind(dist, rng);
std::uniform_int_distribution<ll> distrib(1, p-1);
//distrib(gen);
vl g = po_rho(p-1); vl g = po_rho(p-1);
while(true) { while(true) {
ll c = distrib(gen); ll c = gen(), u = p-1, b = 1;
bool ok = true;
bool ok = true; ll u = p-1;
ll b = 1;
for(auto i:g) { for(auto i:g) {
if(i != b) u = p-1; if(i != b) u = p-1;
ll x = pow(c, u/i, p); ll x = pow(c, u/i, p);
+125 -35
View File
@@ -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. \] \[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$. Non-distinct roots $r$ become polynomial factors, e.g. $a_n = (d_1n + d_2)r^n$.
% \subsection{Trigonometry} \subsection{Trigonometry}
% \begin{align*} \begin{align*}
% \sin(v+w)&{}=\sin v\cos w+\cos v\sin w\\ \sin(v+w)&{}=\sin v\cos w+\cos v\sin w\\
% \cos(v+w)&{}=\cos v\cos w-\sin 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}\\ \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}\\ \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}\\ \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 (V+W)\tan(v-w)/2&{}=(V-W)\tan(v+w)/2
% \end{align*} \end{align*}
% where $V, W$ are lengths of sides opposite angles $v, w$. where $V, W$ are lengths of sides opposite angles $v, w$.
% \begin{align*} \begin{align*}
% a\cos x+b\sin x&=r\cos(x-\phi)\\ a\cos x+b\sin x&=r\cos(x-\phi)\\
% a\sin x+b\cos x&=r\sin(x+\phi) a\sin x+b\cos x&=r\sin(x+\phi)
% \end{align*} \end{align*}
% where $r=\sqrt{a^2+b^2}, \phi=\operatorname{atan2}(b,a)$. where $r=\sqrt{a^2+b^2}, \phi=\operatorname{atan2}(b,a)$.
\subsection{Geometry} \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} \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} \subsubsection{Quadrilaterals}
With side lengths $a,b,c,d$, diagonals $e, f$, diagonals angle $\theta$, area $A$ and 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$: 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$, 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)}$. $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} \subsection{Derivatives/Integrals}
\begin{align*} \begin{align*}
+2 -4
View File
@@ -1,7 +1,5 @@
#define div _div #define div _div
ll div(ll A, ll B) ll div(ll A, ll B) {
{ ll q = A/B; if(A<0) q-=(B>0)-(B<0);
ll q = A/B;
if(A<0) q-=(B>0)-(B<0);
return q; return q;
} }
+15 -4
View File
@@ -1,7 +1,18 @@
const long long rand_L = 1; const long long L = 1, R = 10;
const long long rand_R = 10;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); random_device rd; mt19937 rng(rd());
uniform_int_distribution<int> dist(rand_L, rand_R); uniform_int_distribution<int> dist(L, R);
// discrete_distribution<int> dist({10, 30, 60}); // [0, 2]
// bernoulli_distribution dist(p); // true(p), false(1-p)
// binomial_distribution<int> dist(N, p); // # of success
// geometric_distribution<int> dist(p); // # of failure
// uniform_real_distribution<double> dist(L, R);
// normal_distribution<double> dist(mean, std);
// exponential_distribution<double> dist(lambda); // occur time
// poisson_distribution<int> dist(lambda); // how many?
// chi_squared_distribution<double> dist(df); // 자유도
auto gen = bind(dist, rng); auto gen = bind(dist, rng);
gen(); gen(); gen(); gen(); gen(); gen();
+12
View File
@@ -0,0 +1,12 @@
// https://koosaga.com/301
vi duval(vi &s){
int n=s.size(), i=0; vi v;
while(i<n) { int j=i+1, k=i;
while(j < n && s[k] <= s[j]){
if(s[k] == s[j]) j++, k++;
else if(s[k] < s[j]) j++, k = i;
}
while(i <= k) i += j - k, v.pb(i);
}
return v;
}
+1 -1
View File
@@ -27,4 +27,4 @@ int getCentTree(int s){
return C; return C;
} }
int C = getCentTree(1); cpar[C] = -1; // int C = getCentTree(1); cpar[C] = -1;
+11 -9
View File
@@ -1,14 +1,16 @@
BOJ 1 // BOJ 트리와 쿼리 1
1 i c: i번 c로 . // 1 i c: i번 간선의 비용을 c로 바꾼다.
2 u v: u에서 v로 . // 2 u v: u에서 v로 가는 단순 경로에 존재하는 비용 중에서 가장 큰 것을 출력한다.
int update(vi& seg, int a, int b);
int query(vi& seg, int l, int r);
vi seg;
vi adj[N]; int par[N]; int sz[N]; int d[N]; vi adj[N]; int par[N]; int sz[N]; int d[N];
void dfs1(int s) { void dfs1(int s) {
sz[s] = 1; sz[s] = 1;
for(auto it=adj[s].begin(); it!=adj[s].end(); it++)
if(*it == par[s]) {adj[s].erase(it); break;}
for(auto &i : adj[s]) { for(auto &i : adj[s]) {
par[i] = s; d[i] = d[s] + 1; par[i] = s; d[i] = d[s] + 1;
adj[i].erase(find(all(adj[i]), s));
dfs1(i); sz[s] += sz[i]; dfs1(i); sz[s] += sz[i];
if(sz[i] > sz[adj[s][0]]) swap(adj[s][0], i); if(sz[i] > sz[adj[s][0]]) swap(adj[s][0], i);
} }
@@ -27,14 +29,14 @@ int query(int a,int b) {
int ans = 0; int ans = 0;
while(top[a] != top[b]) { while(top[a] != top[b]) {
if(d[top[a]] > d[top[b]]) swap(a, 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]]; b = par[top[b]];
} }
if(d[a] > d[b]) swap(a, 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); // dfs1(1); dfs2(1);
// forr(i, n) arr[in[i]] = m[{par[i], i}]; init(root, arr); // forr(i, n) arr[in[i]] = m[{par[i], i}]; init(seg, arr);
// q == 1: update(root, in[a], c); // in[a]를 c로 대체 // q == 1: update(seg, in[a], c); // in[a]를 c로 대체
// q == 2: query(a, b); // q == 2: query(a, b);
+38
View File
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << endl
#else
#define dbg(x)
#endif
using ll=long long;
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#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
}
+2 -2
View File
@@ -1,3 +1,3 @@
mkdir {A..M} 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 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 solve_exefile -O2 -Wall && echo "Compile Done" && time ./solve_exefile' alias fast='g++ main.cpp -o main -O2 -Wall && echo "Compile Done" && time ./main'