|
| 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<int></code>, <code>vector<ll></code>, et cetera as an argument. In this document, we unify these notations to <code>suffix_array<T>(vector<T> v)</code>.</p> |
| 90 | +<p>For example, to calculate the suffix array of the integral array $v$ stored in <code>vector<int></code>, we can code as follows.</p> |
| 91 | +<pre><code class="language-cpp">vector<int> sa = suffix_array(v); |
| 92 | +// vector<int> sa = suffix_array<int>(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 <atcoder/scc>; |
| 97 | +using namespace atcoder; |
| 98 | + |
| 99 | +int main() { |
| 100 | + int n; |
| 101 | + scanf("%d", &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 <atcoder/scc>; |
| 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 <atcoder/scc>; |
| 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<Cap>::edge</code> is used to store edges.</p> |
| 133 | +<p>For example, the type of the edges of <code>mf_graph<int></code> is <code>mf_graph<int>::edge</code>. |
| 134 | +If you are not familiar to <code>::</code>, you can use the string <code>mf_graph<int>::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<mf_graph<int>::edge> v; |
| 136 | +mf_graph<int>::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<T> convolution<int m = 998244353>(vector<T> a, vector<T> 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<long long> c = convolution(a, b); |
| 144 | +vector<long long> c = convolution<924844033>(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> |
0 commit comments