Skip to content

Commit 8e67dff

Browse files
committed
deploy: 58ac3a8
1 parent 2c64e8a commit 8e67dff

File tree

90 files changed

+5576
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5576
-0
lines changed

update/document_en/appendix.html

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<!DOCTYPE html>
2+
<html lang="ja">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
7+
<!-- Uikit -->
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link rel="stylesheet" href="lib/uikit.min.css" />
10+
<script src="lib/uikit.min.js"></script>
11+
<script src="lib/uikit-icons.min.js"></script>
12+
<!-- Katex -->
13+
<link rel="stylesheet" href="lib/katex.min.css" />
14+
<script defer src="lib/katex.min.js"></script>
15+
<script defer src="lib/auto-render.min.js"></script>
16+
<!-- Ace editor-->
17+
<script src="lib/ace.js"></script>
18+
19+
<style>
20+
h2 {
21+
border-bottom:1px solid #CCC;
22+
}
23+
</style>
24+
<script>
25+
document.addEventListener("DOMContentLoaded", function () {
26+
renderMathInElement(
27+
document.body, {
28+
delimiters: [
29+
{ left: "$$", right: "$$", display: true },
30+
{ left: "$", right: "$", display: false }],
31+
ignoredTags: [],
32+
})
33+
for (e of document.getElementsByClassName("sample-code")) {
34+
var editor = ace.edit(e);
35+
editor.setOption("maxLines", "Infinity");
36+
editor.setReadOnly(true);
37+
editor.getSession().setMode("ace/mode/c_cpp");
38+
}
39+
});
40+
</script>
41+
</head><body>
42+
<div class="uk-navbar-container" uk-navbar>
43+
<div class="uk-navbar-left">
44+
<a href="./index.html" class="uk-navbar-item uk-logo">AC Library</a>
45+
</div>
46+
</div>
47+
<section class="uk-section">
48+
<div class="uk-container">
49+
<h1>Appendix / FAQ</h1>
50+
<h2>Environments</h2>
51+
<ul>
52+
<li>Do not use the macro beginning with <code>ATCODER_</code>.</li>
53+
<li>Although we aimed to make it work in many environments, it requires some C++ extension. We assume the following.<ul>
54+
<li><code>__int128 / unsigned __int128(g++, clang++)</code> or <code>_mul128 / _umul128(Visual Studio)</code> works.</li>
55+
<li><code>__builtin_(ctz/ctzll/clz/clzll/popcount)(g++, clang++)</code> or <code>_BitScan(Forward/Reverse)(Visual Studio)</code> works.</li>
56+
<li><code>char / short / int / ll</code> and their <code>unsigned</code> types (and <code>signed char</code>) are <code>8 / 16 / 32 / 64</code> bits.</li>
57+
<li>💻 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r0.html">Signed integers are two's complement</a>.</li>
58+
</ul>
59+
</li>
60+
</ul>
61+
<h2>How to Install</h2>
62+
<h3>g++ / clang++</h3>
63+
<p>The easiest way is to put <code>atcoder</code> folder in the same place as <code>main.cpp</code> and execute <code>g++ main.cpp -std=c++14 -I .</code>, as noted in the index. Here, <code>.</code> is the symbol that represents the current directory (you should type a space and a period after <code>I</code>).</p>
64+
<p>If you don't want to copy <code>atcoder</code> folder manually, do as follows.</p>
65+
<ul>
66+
<li>Specify the command like <code>g++ main.cpp -std=c++14 -I /path/to/ac-library</code> (<code>/path/to/ac-library</code> stands for the directory where the downloaded ac-library is located).</li>
67+
<li>Specify the place of <code>atcoder</code> folder by the environment variable <code>CPLUS_INCLUDE_PATH</code> as <code>CPLUS_INCLUDE_PATH="/path/to/ac-library"</code>. (On Windows, type like <code>C:\path\to\ac-library</code> in the field of the variable <code>CPLUS_INCLUDE_PATH</code> on the <a href="https://img.atcoder.jp/practice2/01333b7c5575b09b5868376ef242aa52.png">Window of Environment Variables</a>. Note that, you should use backslashes, not slashes.) Then, you can compile just by <code>g++ main.cpp -std=c++14</code>.</li>
68+
</ul>
69+
<h3>Visual Studio</h3>
70+
<p>Visual Studio 2019 / 2022 is supported. Update it if you are using old Visual Studio.</p>
71+
<p>If Visual Studio is installed, there is a folder like the following.</p>
72+
<ul>
73+
<li><code>C:\Program Files\Microsoft Visual Studio\2022\(Community, Professional or Enterprise)\VC\Tools\MSVC\(Some number, e.g. 14.35.32215)\include</code></li>
74+
<li><code>C:\Program Files (x86)\Microsoft Visual Studio\2019\(Community, Professional or Enterprise)\VC\Tools\MSVC\(Some number, e.g. 14.27.29110)\include</code></li>
75+
</ul>
76+
<p>Copy <code>atcoder</code> folder into it, i.e., put it so that the path will be as follows.</p>
77+
<ul>
78+
<li><code>C:\Program Files\Microsoft Visual Studio\2022\(Community, Professional or Enterprise)\VC\Tools\MSVC\(Some number, e.g. 14.35.32215)\include\atcoder\dsu.hpp</code></li>
79+
</ul>
80+
<h2>How to Submit to Other Online Judge Systems</h2>
81+
<p>We prepared the script <code>expander.py</code> (python3.5 or later).
82+
The code <code>combined.cpp</code>, which can be compiled on other online judge systems, is generated by executing <code>python3 expander.py main.cpp</code>.</p>
83+
<p>Although we tested it, we do not guarantee that it works correctly.</p>
84+
<h2>Preliminaries</h2>
85+
<h3>💻Mark</h3>
86+
<p>This mark represents that the part, e.g., modint, may be difficult to use if you do not know much about C++.
87+
AC Library is designed to be still usable if you ignore the parts with this mark.</p>
88+
<h3>Template Function</h3>
89+
<p>For example, <code>suffix_array(v)</code> can take <code>vector&lt;int&gt;</code>, <code>vector&lt;ll&gt;</code>, et cetera as an argument. In this document, we unify these notations to <code>suffix_array&lt;T&gt;(vector&lt;T&gt; v)</code>.</p>
90+
<p>For example, to calculate the suffix array of the integral array $v$ stored in <code>vector&lt;int&gt;</code>, we can code as follows.</p>
91+
<pre><code class="language-cpp">vector&lt;int&gt; sa = suffix_array(v);
92+
// vector&lt;int&gt; sa = suffix_array&lt;int&gt;(v); : wrong usage
93+
</code></pre>
94+
<h3>Default Constructor</h3>
95+
<p>The structs like <code>scc_graph</code> can be declared not only like the former code, but also like the latter code without initialization.</p>
96+
<pre><code class="language-cpp">#include &lt;atcoder/scc&gt;;
97+
using namespace atcoder;
98+
99+
int main() {
100+
int n;
101+
scanf(&quot;%d&quot;, &amp;n);
102+
scc_graph g(n); // create the graph with n vertices
103+
return 0;
104+
}
105+
</code></pre>
106+
<pre><code class="language-cpp">#include &lt;atcoder/scc&gt;;
107+
using namespace atcoder;
108+
109+
scc_graph g;
110+
111+
int main() {
112+
return 0;
113+
}
114+
</code></pre>
115+
<p>If it is declared in the latter way, the behavior (of the default constructor) is as follows.</p>
116+
<ul>
117+
<li>It takes $O(1)$-time.</li>
118+
<li>The behavior is undefined if the member variables are accessed or the member functions are called.</li>
119+
</ul>
120+
<p>You can also assign a value to the struct later.</p>
121+
<pre><code class="language-cpp">#include &lt;atcoder/scc&gt;;
122+
using namespace atcoder;
123+
124+
scc_graph g;
125+
126+
int main() {
127+
g = scc_graph(10);
128+
return 0;
129+
}
130+
</code></pre>
131+
<h3>The Type of the Edges</h3>
132+
<p>In the graph libraries, the type <code>mf_graph&lt;Cap&gt;::edge</code> is used to store edges.</p>
133+
<p>For example, the type of the edges of <code>mf_graph&lt;int&gt;</code> is <code>mf_graph&lt;int&gt;::edge</code>.
134+
If you are not familiar to <code>::</code>, you can use the string <code>mf_graph&lt;int&gt;::edge</code> in the same manner as <code>int</code> or <code>string</code>, like the following example.</p>
135+
<pre><code class="language-cpp">vector&lt;mf_graph&lt;int&gt;::edge&gt; v;
136+
mf_graph&lt;int&gt;::edge e;
137+
</code></pre>
138+
<h3>Default Template Arguments</h3>
139+
<p>Sometimes the following notation is used, as in the document of convolution.</p>
140+
<pre><code class="language-cpp">vector&lt;T&gt; convolution&lt;int m = 998244353&gt;(vector&lt;T&gt; a, vector&lt;T&gt; b)
141+
</code></pre>
142+
<p>It means the default template argument. As the following example, you can call the function without explicitly specifying <code>m</code>.</p>
143+
<pre><code class="language-cpp">vector&lt;long long&gt; c = convolution(a, b);
144+
vector&lt;long long&gt; c = convolution&lt;924844033&gt;(a, b);
145+
</code></pre>
146+
<p>In the first case, $m$ is automatically set to be $998244353$.
147+
In the second case, $m$ becomes the value that is explicitly specified, which is $924844033$ here.</p>
148+
<h3>💻 explicit specifier</h3>
149+
<p>Constructors of structs except <code>modint</code> are declared with the explicit specifier.</p>
150+
<h2>Precise requirements in Segtree / LazySegtree</h2>
151+
<p>In some situations, the cardinality of algebraic structures for Segtree / LazySegtree would be infinite. In precise meaning, it may break the constraints in the document.</p>
152+
<p>For example, for the typical LazySegtree on $S = \mathrm{int}$ that processes the queries of range max and range addition, $S$ is not closed under addition due to the overflow.
153+
To resolve this problem, it is ensured to work correctly in the following situation.</p>
154+
<h3>Segtree</h3>
155+
<ul>
156+
<li>$S$ is an algebraic structure that satisfies the properties in the document.</li>
157+
<li>$e \in S' \subseteq S$</li>
158+
<li>If the arguments and the results are in $S'$, the types and operations work correctly.</li>
159+
<li>For any moment, every contigurous subsequence $a_l, a_{l+1}, \cdots, a_{r-1}$ satisfies $a_l \cdot a_{l+1} \cdot \ldots \cdot a_{r-1}\in S'$.</li>
160+
</ul>
161+
<h3>LazySegtree</h3>
162+
<ul>
163+
<li>$(S, F)$ is a pair of algebraic structures that satisfies the properties in the document.</li>
164+
<li>$e \in S' \subseteq S, \mathrm{id} \in F' \subseteq F$</li>
165+
<li>If the arguments and the results are in $S'$ or $F'$, the types and operations work correctly.</li>
166+
<li>For any moment, every contigurous subsequence $a_l, a_{l+1}, \cdots, a_{r-1}$ satisfies $a_l \cdot a_{l+1} \cdot \ldots \cdot a_{r-1}\in S'$.</li>
167+
<li>Let us fix an element and denote the maps acted on it by $f_0, f_1, ..., f_{k-1} \in F$ in this order. Then, for every contigurous subsequence $f_l, \cdots, f_{r-1}$, $f_{r-1} \circ f_{l+1} \circ \dots \circ f_{l} \in F'$.</li>
168+
</ul>
169+
<p>Above LazySegtree can naturally be defined as follows, using infinite algebraic structures $S$ and $F$.</p>
170+
<ul>
171+
<li>$S = \mathbb{Z} \cup {-\infty}$</li>
172+
<li>The binary operation $\cdot$ on $S$ is $\mathrm{max}$ and $e = -\infty$.</li>
173+
<li>$F$ is the set of the maps that adds a constant integer ($\mathrm{id}$ is the map that adds $0$).</li>
174+
</ul>
175+
<p>Under some sufficiently small constraints, it can be treated by this library by setting $(S', F')$ as follows.</p>
176+
<ul>
177+
<li>$S' = (\mathbb{Z} \cap (-2^{31}, 2^{31})) \cup {-\infty}$</li>
178+
<li>$S'$ is represented by $\mathrm{int}$. The element $x\in S'$ is represented as $x$ in $\mathrm{int}$ if $x \neq -\infty$ and $-2^{31}$ if $x = -\infty$.</li>
179+
<li>$F'$ is the set of the maps that adds a constant integer in $[-2^{31}, 2^{31})$ and represented naturally using the type $\mathrm{int}$.</li>
180+
</ul>
181+
<h2>The Behavior of maxflow</h2>
182+
<p>Internally, for each edge $e$, it stores the flow amount $f_e$ and the capacity $c_e$.
183+
Let $\mathrm{out}(v)$ and $\mathrm{in}(v)$ be the set of edges starts and ends at $v$, respectively.
184+
For each vertex $v$, let $g(v, f) = \sum_{e \in \mathrm{in}(v)}{f_e} - \sum_{e \in \mathrm{out}(v)}{f_e}$.</p>
185+
<h3><code>flow(s, t)</code></h3>
186+
<p>It changes the flow amount of each edge. Let $f_e$ and $f'_e$ be the flow amount of edge $e$ before and after calling it, respectively.
187+
Precisely, it changes the flow amount as follows.</p>
188+
<ul>
189+
<li>$0 \leq f'_e \leq c_e$</li>
190+
<li>$g(v, f) = g(v, f')$ holds for all vertices $v$ other than $s$ and $t$.</li>
191+
<li>If flow_limit is specified, $g(t, f') - g(t, f) \leq \mathrm{flow\_limit}$.</li>
192+
<li>$g(t, f') - g(t, f)$ is maximized under these conditions. It returns this $g(t, f') - g(t, f)$.</li>
193+
</ul>
194+
<h3><code>min_cut(s)</code></h3>
195+
<p>The residual network is the graph whose edge set is given by gathering $(u, v)$ for each edge $e = (u, v, f_e, c_e)$ with $f_e \lt c_e$ and $(v, u)$ for each edge $e$ with $0 \lt f_e$.
196+
It returns the set of the vertices that is reachable from $s$ in the residual network.</p>
197+
<h3><code>change_edge(i, new_cap, new_flow)</code></h3>
198+
<p>It changes the flow amount and the capacity of the edge $i$ to <code>new_flow</code> and <code>new_cap</code>, respectively. It doesn't change other values.</p>
199+
</div>
200+
</section>
201+
</body>
202+
203+
</html>

update/document_en/convolution.html

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<!DOCTYPE html>
2+
<html lang="ja">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
7+
<!-- Uikit -->
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link rel="stylesheet" href="lib/uikit.min.css" />
10+
<script src="lib/uikit.min.js"></script>
11+
<script src="lib/uikit-icons.min.js"></script>
12+
<!-- Katex -->
13+
<link rel="stylesheet" href="lib/katex.min.css" />
14+
<script defer src="lib/katex.min.js"></script>
15+
<script defer src="lib/auto-render.min.js"></script>
16+
<!-- Ace editor-->
17+
<script src="lib/ace.js"></script>
18+
19+
<style>
20+
h2 {
21+
border-bottom:1px solid #CCC;
22+
}
23+
</style>
24+
<script>
25+
document.addEventListener("DOMContentLoaded", function () {
26+
renderMathInElement(
27+
document.body, {
28+
delimiters: [
29+
{ left: "$$", right: "$$", display: true },
30+
{ left: "$", right: "$", display: false }],
31+
ignoredTags: [],
32+
})
33+
for (e of document.getElementsByClassName("sample-code")) {
34+
var editor = ace.edit(e);
35+
editor.setOption("maxLines", "Infinity");
36+
editor.setReadOnly(true);
37+
editor.getSession().setMode("ace/mode/c_cpp");
38+
}
39+
});
40+
</script>
41+
</head><body>
42+
<div class="uk-navbar-container" uk-navbar>
43+
<div class="uk-navbar-left">
44+
<a href="./index.html" class="uk-navbar-item uk-logo">AC Library</a>
45+
</div>
46+
</div>
47+
<section class="uk-section">
48+
<div class="uk-container">
49+
<h1>Convolution</h1>
50+
<p>It calculates $(+,\times)$ convolution. Given two arrays $a_0, a_1, \cdots, a_{N - 1}$ and $b_0, b_1, \cdots, b_{M - 1}$, it calculates the array $c$ of length $N + M - 1$, defined by</p>
51+
<p>$$c_i = \sum_{j = 0}^i a_j b_{i - j}$$</p>
52+
<h2>convolution</h2>
53+
<pre><code class="language-cpp">(1) vector&lt;T&gt; convolution&lt;int m = 998244353&gt;(vector&lt;T&gt; a, vector&lt;T&gt; b)
54+
💻(2) vector&lt;static_modint&lt;m&gt;&gt; convolution&lt;int m&gt;(vector&lt;static_modint&lt;m&gt;&gt; a, vector&lt;static_modint&lt;m&gt;&gt; b)
55+
</code></pre>
56+
<p>It calculates the convolution in $\bmod m$. It returns an empty array if at least one of $a$ and $b$ are empty.</p>
57+
<p><strong>Constraints</strong></p>
58+
<ul>
59+
<li>$2 \leq m \leq 2 \times 10^9$</li>
60+
<li>$m$ is prime.</li>
61+
<li>There is an integer $c$ with $2^c | (m - 1)$ and $|a| + |b| - 1 \leq 2^c$.</li>
62+
<li>(1) <code>T</code> is <code>int</code>, <code>uint</code>, <code>ll</code>, or <code>ull</code>.</li>
63+
</ul>
64+
<p><strong>Complexity</strong></p>
65+
<ul>
66+
<li>$O(n\log{n} + \log{\mathrm{mod}})$, where $n = |a| + |b|$.</li>
67+
</ul>
68+
<h2>convolution_ll</h2>
69+
<pre><code class="language-cpp">vector&lt;ll&gt; convolution_ll(vector&lt;ll&gt; a, vector&lt;ll&gt; b)
70+
</code></pre>
71+
<p>It calculates the convolution. It returns an empty array if at least one of $a$ and $b$ are empty.</p>
72+
<p><strong>Constraints</strong></p>
73+
<ul>
74+
<li>$|a| + |b| - 1 \leq 2^{24}$</li>
75+
<li>All the elements of the array are in <code>ll</code> after convolution</li>
76+
</ul>
77+
<p><strong>Complexity</strong></p>
78+
<ul>
79+
<li>$O(n\log{n})$, where $n = |a| + |b|$.</li>
80+
</ul>
81+
<h2>Examples</h2>
82+
<h3>AC code of <a href="https://atcoder.jp/contests/practice2/tasks/practice2_f">https://atcoder.jp/contests/practice2/tasks/practice2_f</a></h3>
83+
<div class="sample-code">#include &lt;atcoder/convolution&gt;
84+
#include &lt;atcoder/modint&gt;
85+
#include &lt;cstdio&gt;
86+
87+
using namespace std;
88+
using namespace atcoder;
89+
90+
int main() {
91+
int n, m;
92+
scanf(&#34;%d %d&#34;, &amp;n, &amp;m);
93+
vector&lt;long long&gt; a(n), b(m);
94+
for (int i = 0; i &lt; n; i++) {
95+
scanf(&#34;%lld&#34;, &amp;(a[i]));
96+
}
97+
for (int i = 0; i &lt; m; i++) {
98+
scanf(&#34;%lld&#34;, &amp;(b[i]));
99+
}
100+
101+
vector&lt;long long&gt; c = convolution(a, b);
102+
// or: vector&lt;long long&gt; c = convolution&lt;998244353&gt;(a, b);
103+
104+
for (int i = 0; i &lt; n + m - 1; i++) {
105+
printf(&#34;%lld &#34;, c[i]);
106+
}
107+
printf(&#34;\n&#34;);
108+
109+
return 0;
110+
}
111+
</div>
112+
113+
<h3>AC code of <a href="https://atcoder.jp/contests/practice2/tasks/practice2_f">https://atcoder.jp/contests/practice2/tasks/practice2_f</a></h3>
114+
<div class="sample-code">#include &lt;atcoder/convolution&gt;
115+
#include &lt;atcoder/modint&gt;
116+
#include &lt;cstdio&gt;
117+
118+
using namespace std;
119+
using namespace atcoder;
120+
121+
using mint = modint998244353;
122+
123+
int main() {
124+
int n, m;
125+
scanf(&#34;%d %d&#34;, &amp;n, &amp;m);
126+
vector&lt;mint&gt; a(n), b(m);
127+
for (int i = 0; i &lt; n; i++) {
128+
int x;
129+
scanf(&#34;%d&#34;, &amp;x);
130+
a[i] = x;
131+
}
132+
for (int i = 0; i &lt; m; i++) {
133+
int x;
134+
scanf(&#34;%d&#34;, &amp;x);
135+
b[i] = x;
136+
}
137+
138+
auto c = convolution(a, b);
139+
140+
for (int i = 0; i &lt; n + m - 1; i++) {
141+
printf(&#34;%d &#34;, c[i].val());
142+
}
143+
printf(&#34;\n&#34;);
144+
145+
return 0;
146+
}
147+
</div>
148+
</div>
149+
</section>
150+
</body>
151+
152+
</html>

0 commit comments

Comments
 (0)