From 61fbfd65158f4aabf7ee97121780fae77a699b61 Mon Sep 17 00:00:00 2001 From: fffelix-huang <72808219+fffelix-huang@users.noreply.github.com> Date: Wed, 31 May 2023 00:12:41 +0800 Subject: [PATCH 01/17] Fixed typo --- atcoder/lazysegtree.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atcoder/lazysegtree.hpp b/atcoder/lazysegtree.hpp index c858663..66cc8de 100644 --- a/atcoder/lazysegtree.hpp +++ b/atcoder/lazysegtree.hpp @@ -26,7 +26,7 @@ struct lazy_segtree { "e must work as S()"); static_assert( std::is_convertible_v>, - "mapping must work as F(F, S)"); + "mapping must work as S(F, S)"); static_assert( std::is_convertible_v>, "compostiion must work as F(F, F)"); From bc76aabcdf364c07b64865e30e94a16d43077c97 Mon Sep 17 00:00:00 2001 From: Rezwan Arefin Date: Sat, 29 Jul 2023 21:43:09 +0800 Subject: [PATCH 02/17] Fix redundant copy in convolution --- atcoder/convolution.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atcoder/convolution.hpp b/atcoder/convolution.hpp index d206205..20a9355 100644 --- a/atcoder/convolution.hpp +++ b/atcoder/convolution.hpp @@ -223,8 +223,8 @@ std::vector convolution(std::vector&& a, std::vector&& b) { int z = (int)internal::bit_ceil((unsigned int)(n + m - 1)); assert((mint::mod() - 1) % z == 0); - if (std::min(n, m) <= 60) return convolution_naive(a, b); - return internal::convolution_fft(a, b); + if (std::min(n, m) <= 60) return convolution_naive(std::move(a), std::move(b)); + return internal::convolution_fft(std::move(a), std::move(b)); } template * = nullptr> std::vector convolution(const std::vector& a, From 7d6622e9f1fd274e7f6c2ff7526e4df269d36b26 Mon Sep 17 00:00:00 2001 From: Siarhei Siamashka Date: Thu, 14 Dec 2023 02:10:01 +0200 Subject: [PATCH 03/17] expander.py: trace line numbers back to the original source file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the "#line" directives, it's possible to allow compilers to report line numbers from the original source file. At least GCC and Clang support this. It's useful for tracing the compilation error locations back to the original file. Example: #include #include int main() { lazy_segtree seg(arr); } == The current default behaviour: == $ ./expander.py example.cpp $ g++ combined.cpp combined.cpp: In function ‘int main()’: combined.cpp:263:3: error: ‘lazy_segtree’ was not declared in this scope; did you mean ‘atcoder::lazy_segtree’? == With the new '--origname' option: == $ ./expander.py --origname=example.cpp example.cpp $ g++ combined.cpp example.cpp: In function ‘int main()’: example.cpp:4:3: error: ‘lazy_segtree’ was not declared in this scope; did you mean ‘atcoder::lazy_segtree’? --- expander.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/expander.py b/expander.py index ff773da..e4b87f3 100755 --- a/expander.py +++ b/expander.py @@ -63,14 +63,18 @@ def expand_acl(self, acl_file_path: Path) -> List[str]: result.append(line) return result - def expand(self, source: str) -> str: + def expand(self, source: str, origname) -> str: self.included = set() result = [] # type: List[str] + linenum = 0 for line in source.splitlines(): + linenum += 1 m = self.atcoder_include.match(line) if m: acl_path = self.find_acl(m.group(1)) result.extend(self.expand_acl(acl_path)) + if origname: + result.append('#line ' + str(linenum + 1) + ' "' + origname + '"') continue result.append(line) @@ -88,6 +92,8 @@ def expand(self, source: str) -> str: parser.add_argument('-c', '--console', action='store_true', help='Print to Console') parser.add_argument('--lib', help='Path to Atcoder Library') + parser.add_argument('--origname', help='report line numbers from the original ' + + 'source file in GCC/Clang error messages') opts = parser.parse_args() lib_paths = [] @@ -99,7 +105,7 @@ def expand(self, source: str) -> str: lib_paths.append(Path.cwd()) expander = Expander(lib_paths) source = open(opts.source).read() - output = expander.expand(source) + output = expander.expand(source, opts.origname) if opts.console: print(output) From a2f140c6d49c349a973dad2068c4c6bcf669083d Mon Sep 17 00:00:00 2001 From: nu50218 <40682920+nu50218@users.noreply.github.com> Date: Wed, 27 Dec 2023 21:31:06 +0900 Subject: [PATCH 04/17] fix typo in lazysegtree.hpp --- atcoder/lazysegtree.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atcoder/lazysegtree.hpp b/atcoder/lazysegtree.hpp index c858663..eef0f8d 100644 --- a/atcoder/lazysegtree.hpp +++ b/atcoder/lazysegtree.hpp @@ -29,7 +29,7 @@ struct lazy_segtree { "mapping must work as F(F, S)"); static_assert( std::is_convertible_v>, - "compostiion must work as F(F, F)"); + "composition must work as F(F, F)"); static_assert(std::is_convertible_v>, "id must work as F()"); From 520f3623d5b1f97a178e916d5df7788b8924e6eb Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Tue, 18 Jun 2024 21:24:32 -0700 Subject: [PATCH 05/17] remove unsigned from the changed value of modint.val() --- atcoder/modint.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atcoder/modint.hpp b/atcoder/modint.hpp index cfcf815..44f968b 100644 --- a/atcoder/modint.hpp +++ b/atcoder/modint.hpp @@ -48,7 +48,7 @@ struct static_modint : internal::static_modint_base { _v = (unsigned int)(v % umod()); } - unsigned int val() const { return _v; } + int val() const { return _v; } mint& operator++() { _v++; @@ -165,7 +165,7 @@ template struct dynamic_modint : internal::modint_base { _v = (unsigned int)(v % mod()); } - unsigned int val() const { return _v; } + int val() const { return _v; } mint& operator++() { _v++; From c3860038dcd1dcbe05c74181f381b4eb6aa33bbb Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Tue, 18 Jun 2024 21:28:06 -0700 Subject: [PATCH 06/17] update actions --- .github/workflows/document.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/document.yml b/.github/workflows/document.yml index a2f9b23..1a9a93d 100644 --- a/.github/workflows/document.yml +++ b/.github/workflows/document.yml @@ -31,9 +31,9 @@ jobs: VERSION: ${{ steps.version.outputs.VERSION_NAME }} - name: Publish to github pages if: ${{ github.event_name == 'push' }} - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: - deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} + github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./tools/generated destination_dir: ${{ steps.version.outputs.VERSION_NAME }} - name: Upload zip From 748a56490fab5b6486240f5dd4d84cecc5fe508b Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Tue, 18 Jun 2024 21:32:19 -0700 Subject: [PATCH 07/17] fix --- atcoder/convolution.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atcoder/convolution.hpp b/atcoder/convolution.hpp index 20a9355..de3f1ae 100644 --- a/atcoder/convolution.hpp +++ b/atcoder/convolution.hpp @@ -130,7 +130,7 @@ void butterfly_inv(std::vector& a) { auto r = a[i + offset + p]; a[i + offset] = l + r; a[i + offset + p] = - (unsigned long long)(mint::mod() + l.val() - r.val()) * + (unsigned long long)((unsigned int)(l.val() - r.val()) + mint::mod()) * irot.val(); ; } From c70d3c56079b0bc3483f657daa296de3fce96554 Mon Sep 17 00:00:00 2001 From: Gabriel Wu Date: Tue, 7 Jan 2025 15:15:10 +0800 Subject: [PATCH 08/17] Fix English version of lazysegtree doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compared to the Japanese version, two emojis (💻) are missing, and extra spaces are shown. This commit fixes this issue. --- document_en/lazysegtree.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document_en/lazysegtree.md b/document_en/lazysegtree.md index 2f7738e..8d7f43c 100644 --- a/document_en/lazysegtree.md +++ b/document_en/lazysegtree.md @@ -126,7 +126,7 @@ It returns `op(a[0], ..., a[n - 1])`, assuming the properties of the monoid. It ```cpp (1) int seg.max_right(int l) -(2 ) int seg.max_right(int l, G g) +(2💻) int seg.max_right(int l, G g) ``` - (1): It applies a binary search on the segment tree. The function `bool g(S x)` should be defined. @@ -153,7 +153,7 @@ If `g` is monotone, this is the maximum `r` that satisfies `g(op(a[l], a[l + 1], ```cpp (1) int seg.min_left(int r) -(2 ) int seg.min_left(int r, G g) +(2💻) int seg.min_left(int r, G g) ``` - (1): It applies a binary search on the segment tree. The function `bool g(S x)` should be defined. From bf1cabd0109f7deeefa29b15f8217fdcbf0d69a0 Mon Sep 17 00:00:00 2001 From: tatyam Date: Mon, 3 Feb 2025 22:56:37 +0900 Subject: [PATCH 09/17] Add assertation in `atcoder::lcp_array` --- atcoder/string.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atcoder/string.hpp b/atcoder/string.hpp index 2c68258..5da8963 100644 --- a/atcoder/string.hpp +++ b/atcoder/string.hpp @@ -213,10 +213,12 @@ std::vector suffix_array(const std::string& s) { template std::vector lcp_array(const std::vector& s, const std::vector& sa) { + assert(s.size() == sa.size()); int n = int(s.size()); assert(n >= 1); std::vector rnk(n); for (int i = 0; i < n; i++) { + assert(0 <= sa[i] && sa[i] < n); rnk[sa[i]] = i; } std::vector lcp(n - 1); From 62959169970fdff9cad4b0017b776731e522355a Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 02:46:49 +0900 Subject: [PATCH 10/17] update github actions --- .github/workflows/document.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/document.yml b/.github/workflows/document.yml index a2f9b23..be6403c 100644 --- a/.github/workflows/document.yml +++ b/.github/workflows/document.yml @@ -37,7 +37,7 @@ jobs: publish_dir: ./tools/generated destination_dir: ${{ steps.version.outputs.VERSION_NAME }} - name: Upload zip - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ac-library path: tools/ac-library.zip \ No newline at end of file From 47196432fbe13fc95c185543b27079a23f79f222 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 02:50:15 +0900 Subject: [PATCH 11/17] upgrade python version --- .github/workflows/expander.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/expander.yml b/.github/workflows/expander.yml index 1f7049c..3fef573 100644 --- a/.github/workflows/expander.yml +++ b/.github/workflows/expander.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 7344efb11e8a92d319559671605a5f1f3cce28b8 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 02:54:33 +0900 Subject: [PATCH 12/17] update --- .github/workflows/document.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/document.yml b/.github/workflows/document.yml index be6403c..040affd 100644 --- a/.github/workflows/document.yml +++ b/.github/workflows/document.yml @@ -31,9 +31,9 @@ jobs: VERSION: ${{ steps.version.outputs.VERSION_NAME }} - name: Publish to github pages if: ${{ github.event_name == 'push' }} - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: - deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} + deploy_key: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./tools/generated destination_dir: ${{ steps.version.outputs.VERSION_NAME }} - name: Upload zip From 58ac3a8712a5516a1ebba933bc0f8174d7de6cf5 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 02:58:33 +0900 Subject: [PATCH 13/17] fix --- .github/workflows/document.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/document.yml b/.github/workflows/document.yml index 040affd..eae3cb9 100644 --- a/.github/workflows/document.yml +++ b/.github/workflows/document.yml @@ -33,7 +33,7 @@ jobs: if: ${{ github.event_name == 'push' }} uses: peaceiris/actions-gh-pages@v4 with: - deploy_key: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./tools/generated destination_dir: ${{ steps.version.outputs.VERSION_NAME }} - name: Upload zip From 22db9356b6bb341239973f20dc45615b9881c7fa Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 03:52:08 +0900 Subject: [PATCH 14/17] fix/issue182 --- document_en/fenwicktree.md | 2 +- document_en/mincostflow.md | 2 +- document_ja/fenwicktree.md | 4 ++-- document_ja/mincostflow.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/document_en/fenwicktree.md b/document_en/fenwicktree.md index 7539bfa..306353b 100644 --- a/document_en/fenwicktree.md +++ b/document_en/fenwicktree.md @@ -1,6 +1,6 @@ # Fenwick Tree -Given an array of length $N$, it processes the following queries in $O(\log N)$ time. +Given an array of length $n$, it processes the following queries in $O(\log n)$ time. - Updating an element - Calculating the sum of the elements of an interval diff --git a/document_en/mincostflow.md b/document_en/mincostflow.md index 95bb20e..e4cd6f9 100644 --- a/document_en/mincostflow.md +++ b/document_en/mincostflow.md @@ -66,7 +66,7 @@ Let $g$ be a function such that $g(x)$ is the cost of the minimum cost $s-t$ flo It returns $g$ as the list of the changepoints, that satisfies the followings. - The first element of the list is $(0, 0)$. -- Both of `.first` and `.second` are strictly increasing. +- `.first` is strictly increasing and `.second` is non-descreasing. - No three changepoints are on the same line. - (1) The last element of the list is $(x, g(x))$, where $x$ is the maximum amount of the $s-t$ flow. - (2) The last element of the list is $(y, g(y))$, where $y = \min(x, \mathrm{flow\\_limit})$. diff --git a/document_ja/fenwicktree.md b/document_ja/fenwicktree.md index 9206b59..251edb2 100644 --- a/document_ja/fenwicktree.md +++ b/document_ja/fenwicktree.md @@ -1,11 +1,11 @@ # Fenwick Tree -長さ $N$ の配列に対し、 +長さ $n$ の配列に対し、 - 要素の $1$ 点変更 - 区間の要素の総和 -を $O(\log N)$ で求めることが出来るデータ構造です。 +を $O(\log n)$ で求めることが出来るデータ構造です。 ## コンストラクタ diff --git a/document_ja/mincostflow.md b/document_ja/mincostflow.md index 0428b77..42aac65 100644 --- a/document_ja/mincostflow.md +++ b/document_ja/mincostflow.md @@ -66,7 +66,7 @@ vector> graph.slope(int s, int t, Cap flow_limit); 返り値に流量とコストの関係の折れ線が入る。全ての $x$ について、流量 $x$ の時の最小コストを $g(x)$ とすると、$(x, g(x))$ は返り値を折れ線として見たものに含まれる。 - 返り値の最初の要素は $(0, 0)$ -- 返り値の`.first`、`.second`は共に狭義単調増加 +- 返り値の`.first` は狭義単調増加、`.second`は広義単調増加 - 3点が同一線上にあることはない - (1) 返り値の最後の要素は最大流量 $x$ として $(x, g(x))$ - (2) 返り値の最後の要素は $y = \min(x, \mathrm{flow\\_limit})$ として $(y, g(y))$ From 95a08b707f3be328ec12f9c2f8230b630839870b Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 03:54:30 +0900 Subject: [PATCH 15/17] fix typo --- document_en/mincostflow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document_en/mincostflow.md b/document_en/mincostflow.md index e4cd6f9..49be78a 100644 --- a/document_en/mincostflow.md +++ b/document_en/mincostflow.md @@ -66,7 +66,7 @@ Let $g$ be a function such that $g(x)$ is the cost of the minimum cost $s-t$ flo It returns $g$ as the list of the changepoints, that satisfies the followings. - The first element of the list is $(0, 0)$. -- `.first` is strictly increasing and `.second` is non-descreasing. +- `.first` is strictly increasing and `.second` is non-decreasing. - No three changepoints are on the same line. - (1) The last element of the list is $(x, g(x))$, where $x$ is the maximum amount of the $s-t$ flow. - (2) The last element of the list is $(y, g(y))$, where $y = \min(x, \mathrm{flow\\_limit})$. From 2d2e5c8f8e346be4018b60a1ea24b71d02b6ba18 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Sun, 20 Apr 2025 03:55:25 +0900 Subject: [PATCH 16/17] fix segtree doc --- document_en/segtree.md | 2 +- document_ja/segtree.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/document_en/segtree.md b/document_en/segtree.md index d9b8020..3a200cd 100644 --- a/document_en/segtree.md +++ b/document_en/segtree.md @@ -5,7 +5,7 @@ It is the data structure for [monoids](https://en.wikipedia.org/wiki/Monoid) $(S - associativity: $(a \cdot b) \cdot c$ = $a \cdot (b \cdot c)$ for all $a, b, c \in S$ - existence of the identity element: $a \cdot e$ = $e \cdot a$ = $a$ for all $a \in S$ -Given an array $S$ of length $N$, it processes the following queries in $O(\log N)$ time (see [Appendix](./appendix.html) for further details). +Given an array $S$ of length $n$, it processes the following queries in $O(\log n)$ time (see [Appendix](./appendix.html) for further details). - Updating an element - Calculating the product of the elements of an interval diff --git a/document_ja/segtree.md b/document_ja/segtree.md index e989100..f1fdde7 100644 --- a/document_ja/segtree.md +++ b/document_ja/segtree.md @@ -7,12 +7,12 @@ を満たす代数構造に対し使用できるデータ構造です。 -長さ $N$ の $S$ の配列に対し、 +長さ $n$ の $S$ の配列に対し、 - 要素の $1$ 点変更 - 区間の要素の総積の取得 -を $O(\log N)$ で行うことが出来ます。詳細な要件は [Appendix](./appendix.html) を参照してください。 +を $O(\log n)$ で行うことが出来ます。詳細な要件は [Appendix](./appendix.html) を参照してください。 また、このライブラリはオラクルとして`op, e`の2種類を使用しますが、これらが定数時間で動くものと仮定したときの計算量を記述します。オラクル内部の計算量が $O(f(n))$ である場合はすべての計算量が $O(f(n))$ 倍となります。 From ad80e6299c6028f43cde685d3fa1de76f2a04761 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Fri, 2 May 2025 01:43:50 +0900 Subject: [PATCH 17/17] fix dsu.leader to avoid multiple assert checks --- atcoder/dsu.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/atcoder/dsu.hpp b/atcoder/dsu.hpp index 4bc453f..5776da6 100644 --- a/atcoder/dsu.hpp +++ b/atcoder/dsu.hpp @@ -35,8 +35,7 @@ struct dsu { int leader(int a) { assert(0 <= a && a < _n); - if (parent_or_size[a] < 0) return a; - return parent_or_size[a] = leader(parent_or_size[a]); + return _leader(a); } int size(int a) { @@ -69,6 +68,11 @@ struct dsu { // root node: -1 * component size // otherwise: parent std::vector parent_or_size; + + int _leader(int a) { + if (parent_or_size[a] < 0) return a; + return parent_or_size[a] = _leader(parent_or_size[a]); + } }; } // namespace atcoder