update ucpc2026
This commit is contained in:
+8
-18
@@ -1,32 +1,26 @@
|
||||
namespace GMS {
|
||||
template<ll mod>
|
||||
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<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");
|
||||
int n = a.size(), j = 0;
|
||||
|
||||
assert((n & -n) == n && (mod-1)%n == 0);
|
||||
|
||||
for(int i=1; i<n; i++) {
|
||||
int bit = (n >> 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<ll> root[30], iroot[30];
|
||||
static vl root[30], iroot[30];
|
||||
for(int st=1; (1<<st) <= n; st++) {
|
||||
if(root[st].empty()) {
|
||||
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);
|
||||
|
||||
for(int st = 1; (1<<st) <= n; st++) {
|
||||
int i = 1<<st; //int step = n / 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);
|
||||
|
||||
ntt<mod, w>(A); ntt<mod, w>(B);
|
||||
|
||||
fors(i, 0, t-1) A[i] = A[i]*B[i]%mod;
|
||||
|
||||
ntt<mod, w>(A, true);
|
||||
A.resize(n+m-1);
|
||||
|
||||
return A;
|
||||
return A.resize(n+m-1), A;
|
||||
}
|
||||
} // namespace GMS
|
||||
@@ -51,7 +51,7 @@ struct Qring : public vl {
|
||||
}
|
||||
friend poly operator*(const poly& A, const poly& 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;
|
||||
}
|
||||
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<mod>(ret[idx], mod-2); poly g;
|
||||
int n = ret.size();
|
||||
ll c = ret[idx]; ll ic = pow<mod>(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<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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ll> distrib(1, p-1);
|
||||
|
||||
//distrib(gen);
|
||||
uniform_int_distribution<ll> 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);
|
||||
|
||||
+125
-35
@@ -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*}
|
||||
|
||||
Reference in New Issue
Block a user