Skip to content

Commit

Permalink
deploy: d8ca7f2
Browse files Browse the repository at this point in the history
  • Loading branch information
yosupo06 committed Apr 11, 2023
1 parent c587895 commit 58da5e5
Show file tree
Hide file tree
Showing 90 changed files with 5,574 additions and 0 deletions.
203 changes: 203 additions & 0 deletions v1.5.1/document_en/appendix.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<!DOCTYPE html>
<html lang="ja">

<head>
<meta charset="UTF-8">

<!-- Uikit -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="lib/uikit.min.css" />
<script src="lib/uikit.min.js"></script>
<script src="lib/uikit-icons.min.js"></script>
<!-- Katex -->
<link rel="stylesheet" href="lib/katex.min.css" />
<script defer src="lib/katex.min.js"></script>
<script defer src="lib/auto-render.min.js"></script>
<!-- Ace editor-->
<script src="lib/ace.js"></script>

<style>
h2 {
border-bottom:1px solid #CCC;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function () {
renderMathInElement(
document.body, {
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "$", right: "$", display: false }],
ignoredTags: [],
})
for (e of document.getElementsByClassName("sample-code")) {
var editor = ace.edit(e);
editor.setOption("maxLines", "Infinity");
editor.setReadOnly(true);
editor.getSession().setMode("ace/mode/c_cpp");
}
});
</script>
</head><body>
<div class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<a href="./index.html" class="uk-navbar-item uk-logo">AC Library</a>
</div>
</div>
<section class="uk-section">
<div class="uk-container">
<h1>Appendix / FAQ</h1>
<h2>Environments</h2>
<ul>
<li>Do not use the macro beginning with <code>ATCODER_</code>.</li>
<li>Although we aimed to make it work in many environments, it requires some C++ extension. We assume the following.<ul>
<li><code>__int128 / unsigned __int128(g++, clang++)</code> or <code>_mul128 / _umul128(Visual Studio)</code> works.</li>
<li><code>__builtin_(ctz/ctzll/clz/clzll/popcount)(g++, clang++)</code> or <code>_BitScan(Forward/Reverse)(Visual Studio)</code> works.</li>
<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>
<li>💻 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r0.html">Signed integers are two's complement</a>.</li>
</ul>
</li>
</ul>
<h2>How to Install</h2>
<h3>g++ / clang++</h3>
<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>
<p>If you don't want to copy <code>atcoder</code> folder manually, do as follows.</p>
<ul>
<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>
<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>
</ul>
<h3>Visual Studio</h3>
<p>Visual Studio 2019 / 2022 is supported. Update it if you are using old Visual Studio.</p>
<p>If Visual Studio is installed, there is a folder like the following.</p>
<ul>
<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>
<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>
</ul>
<p>Copy <code>atcoder</code> folder into it, i.e., put it so that the path will be as follows.</p>
<ul>
<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>
</ul>
<h2>How to Submit to Other Online Judge Systems</h2>
<p>We prepared the script <code>expander.py</code> (python3.5 or later).
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>
<p>Although we tested it, we do not guarantee that it works correctly.</p>
<h2>Preliminaries</h2>
<h3>💻Mark</h3>
<p>This mark represents that the part, e.g., modint, may be difficult to use if you do not know much about C++.
AC Library is designed to be still usable if you ignore the parts with this mark.</p>
<h3>Template Function</h3>
<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>
<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>
<pre><code class="language-cpp">vector&lt;int&gt; sa = suffix_array(v);
// vector&lt;int&gt; sa = suffix_array&lt;int&gt;(v); : wrong usage
</code></pre>
<h3>Default Constructor</h3>
<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>
<pre><code class="language-cpp">#include &lt;atcoder/scc&gt;;
using namespace atcoder;

int main() {
int n;
scanf(&quot;%d&quot;, &amp;n);
scc_graph g(n); // create the graph with n vertices
return 0;
}
</code></pre>
<pre><code class="language-cpp">#include &lt;atcoder/scc&gt;;
using namespace atcoder;

scc_graph g;

int main() {
return 0;
}
</code></pre>
<p>If it is declared in the latter way, the behavior (of the default constructor) is as follows.</p>
<ul>
<li>It takes $O(1)$-time.</li>
<li>The behavior is undefined if the member variables are accessed or the member functions are called.</li>
</ul>
<p>You can also assign a value to the struct later.</p>
<pre><code class="language-cpp">#include &lt;atcoder/scc&gt;;
using namespace atcoder;

scc_graph g;

int main() {
g = scc_graph(10);
return 0;
}
</code></pre>
<h3>The Type of the Edges</h3>
<p>In the graph libraries, the type <code>mf_graph&lt;Cap&gt;::edge</code> is used to store edges.</p>
<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>.
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>
<pre><code class="language-cpp">vector&lt;mf_graph&lt;int&gt;::edge&gt; v;
mf_graph&lt;int&gt;::edge e;
</code></pre>
<h3>Default Template Arguments</h3>
<p>Sometimes the following notation is used, as in the document of convolution.</p>
<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)
</code></pre>
<p>It means the default template argument. As the following example, you can call the function without explicitly specifying <code>m</code>.</p>
<pre><code class="language-cpp">vector&lt;long long&gt; c = convolution(a, b);
vector&lt;long long&gt; c = convolution&lt;924844033&gt;(a, b);
</code></pre>
<p>In the first case, $m$ is automatically set to be $998244353$.
In the second case, $m$ becomes the value that is explicitly specified, which is $924844033$ here.</p>
<h3>💻 explicit specifier</h3>
<p>Constructors of structs except <code>modint</code> are declared with the explicit specifier.</p>
<h2>Precise requirements in Segtree / LazySegtree</h2>
<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>
<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.
To resolve this problem, it is ensured to work correctly in the following situation.</p>
<h3>Segtree</h3>
<ul>
<li>$S$ is an algebraic structure that satisfies the properties in the document.</li>
<li>$e \in S' \subseteq S$</li>
<li>If the arguments and the results are in $S'$, the types and operations work correctly.</li>
<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>
</ul>
<h3>LazySegtree</h3>
<ul>
<li>$(S, F)$ is a pair of algebraic structures that satisfies the properties in the document.</li>
<li>$e \in S' \subseteq S, \mathrm{id} \in F' \subseteq F$</li>
<li>If the arguments and the results are in $S'$ or $F'$, the types and operations work correctly.</li>
<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>
<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>
</ul>
<p>Above LazySegtree can naturally be defined as follows, using infinite algebraic structures $S$ and $F$.</p>
<ul>
<li>$S = \mathbb{Z} \cup {-\infty}$</li>
<li>The binary operation $\cdot$ on $S$ is $\mathrm{max}$ and $e = -\infty$.</li>
<li>$F$ is the set of the maps that adds a constant integer ($\mathrm{id}$ is the map that adds $0$).</li>
</ul>
<p>Under some sufficiently small constraints, it can be treated by this library by setting $(S', F')$ as follows.</p>
<ul>
<li>$S' = (\mathbb{Z} \cap (-2^{31}, 2^{31})) \cup {-\infty}$</li>
<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>
<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>
</ul>
<h2>The Behavior of maxflow</h2>
<p>Internally, for each edge $e$, it stores the flow amount $f_e$ and the capacity $c_e$.
Let $\mathrm{out}(v)$ and $\mathrm{in}(v)$ be the set of edges starts and ends at $v$, respectively.
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>
<h3><code>flow(s, t)</code></h3>
<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.
Precisely, it changes the flow amount as follows.</p>
<ul>
<li>$0 \leq f'_e \leq c_e$</li>
<li>$g(v, f) = g(v, f')$ holds for all vertices $v$ other than $s$ and $t$.</li>
<li>If flow_limit is specified, $g(t, f') - g(t, f) \leq \mathrm{flow\_limit}$.</li>
<li>$g(t, f') - g(t, f)$ is maximized under these conditions. It returns this $g(t, f') - g(t, f)$.</li>
</ul>
<h3><code>min_cut(s)</code></h3>
<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$.
It returns the set of the vertices that is reachable from $s$ in the residual network.</p>
<h3><code>change_edge(i, new_cap, new_flow)</code></h3>
<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>
</div>
</section>
</body>

</html>
152 changes: 152 additions & 0 deletions v1.5.1/document_en/convolution.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<!DOCTYPE html>
<html lang="ja">

<head>
<meta charset="UTF-8">

<!-- Uikit -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="lib/uikit.min.css" />
<script src="lib/uikit.min.js"></script>
<script src="lib/uikit-icons.min.js"></script>
<!-- Katex -->
<link rel="stylesheet" href="lib/katex.min.css" />
<script defer src="lib/katex.min.js"></script>
<script defer src="lib/auto-render.min.js"></script>
<!-- Ace editor-->
<script src="lib/ace.js"></script>

<style>
h2 {
border-bottom:1px solid #CCC;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function () {
renderMathInElement(
document.body, {
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "$", right: "$", display: false }],
ignoredTags: [],
})
for (e of document.getElementsByClassName("sample-code")) {
var editor = ace.edit(e);
editor.setOption("maxLines", "Infinity");
editor.setReadOnly(true);
editor.getSession().setMode("ace/mode/c_cpp");
}
});
</script>
</head><body>
<div class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<a href="./index.html" class="uk-navbar-item uk-logo">AC Library</a>
</div>
</div>
<section class="uk-section">
<div class="uk-container">
<h1>Convolution</h1>
<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>
<p>$$c_i = \sum_{j = 0}^i a_j b_{i - j}$$</p>
<h2>convolution</h2>
<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)
💻(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)
</code></pre>
<p>It calculates the convolution in $\bmod m$. It returns an empty array if at least one of $a$ and $b$ are empty.</p>
<p><strong>Constraints</strong></p>
<ul>
<li>$2 \leq m \leq 2 \times 10^9$</li>
<li>$m$ is prime.</li>
<li>There is an integer $c$ with $2^c | (m - 1)$ and $|a| + |b| - 1 \leq 2^c$.</li>
<li>(1) <code>T</code> is <code>int</code>, <code>uint</code>, <code>ll</code>, or <code>ull</code>.</li>
</ul>
<p><strong>Complexity</strong></p>
<ul>
<li>$O(n\log{n} + \log{\mathrm{mod}})$, where $n = |a| + |b|$.</li>
</ul>
<h2>convolution_ll</h2>
<pre><code class="language-cpp">vector&lt;ll&gt; convolution_ll(vector&lt;ll&gt; a, vector&lt;ll&gt; b)
</code></pre>
<p>It calculates the convolution. It returns an empty array if at least one of $a$ and $b$ are empty.</p>
<p><strong>Constraints</strong></p>
<ul>
<li>$|a| + |b| - 1 \leq 2^{24}$</li>
<li>All the elements of the array are in <code>ll</code> after convolution</li>
</ul>
<p><strong>Complexity</strong></p>
<ul>
<li>$O(n\log{n})$, where $n = |a| + |b|$.</li>
</ul>
<h2>Examples</h2>
<h3>AC code of <a href="https://atcoder.jp/contests/practice2/tasks/practice2_f">https://atcoder.jp/contests/practice2/tasks/practice2_f</a></h3>
<div class="sample-code">#include &lt;atcoder/convolution&gt;
#include &lt;atcoder/modint&gt;
#include &lt;cstdio&gt;

using namespace std;
using namespace atcoder;

int main() {
int n, m;
scanf(&#34;%d %d&#34;, &amp;n, &amp;m);
vector&lt;long long&gt; a(n), b(m);
for (int i = 0; i &lt; n; i++) {
scanf(&#34;%lld&#34;, &amp;(a[i]));
}
for (int i = 0; i &lt; m; i++) {
scanf(&#34;%lld&#34;, &amp;(b[i]));
}

vector&lt;long long&gt; c = convolution(a, b);
// or: vector&lt;long long&gt; c = convolution&lt;998244353&gt;(a, b);

for (int i = 0; i &lt; n + m - 1; i++) {
printf(&#34;%lld &#34;, c[i]);
}
printf(&#34;\n&#34;);

return 0;
}
</div>

<h3>AC code of <a href="https://atcoder.jp/contests/practice2/tasks/practice2_f">https://atcoder.jp/contests/practice2/tasks/practice2_f</a></h3>
<div class="sample-code">#include &lt;atcoder/convolution&gt;
#include &lt;atcoder/modint&gt;
#include &lt;cstdio&gt;

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
int n, m;
scanf(&#34;%d %d&#34;, &amp;n, &amp;m);
vector&lt;mint&gt; a(n), b(m);
for (int i = 0; i &lt; n; i++) {
int x;
scanf(&#34;%d&#34;, &amp;x);
a[i] = x;
}
for (int i = 0; i &lt; m; i++) {
int x;
scanf(&#34;%d&#34;, &amp;x);
b[i] = x;
}

auto c = convolution(a, b);

for (int i = 0; i &lt; n + m - 1; i++) {
printf(&#34;%d &#34;, c[i].val());
}
printf(&#34;\n&#34;);

return 0;
}
</div>
</div>
</section>
</body>

</html>
Loading

0 comments on commit 58da5e5

Please sign in to comment.