Skip to content

Commit

Permalink
[auto-verifier] docs commit d4836fa
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow authored Sep 22, 2024
1 parent 7001e45 commit 03628bb
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 431 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Except such snippets, the programs written by the owner of the repo is under the

## Formatting

`clang-format-16` is used to lint `.cpp` / `.hpp` files. Default configuration file is `.clang-format`. See [formatter.yml](.github/workflows/formatter.yml) for detail.
`clang-format-19` is used to lint `.cpp` / `.hpp` files. Default configuration file is `.clang-format`. See [formatter.yml](.github/workflows/formatter.yml) for detail.
63 changes: 31 additions & 32 deletions convolution/fft_double.hpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ data:
- http://kirika-comp.hatenablog.com/entry/2018/03/12/210446
- https://atcoder.jp/contests/atc001/submissions/9243440
bundledCode: "#line 2 \"convolution/fft_double.hpp\"\n#include <complex>\n#include\
\ <utility>\n#include <vector>\n\n// CUT begin\n// Convolution by FFT (Fast Fourier\
\ Transform)\n// Algorithm based on http://kirika-comp.hatenablog.com/entry/2018/03/12/210446\n\
\ <utility>\n#include <vector>\n\n// Convolution by FFT (Fast Fourier Transform)\n\
// Algorithm based on http://kirika-comp.hatenablog.com/entry/2018/03/12/210446\n\
// Verified: ATC001C (168 ms) https://atcoder.jp/contests/atc001/submissions/9243440\n\
using cmplx = std::complex<double>;\nvoid fft(int N, std::vector<cmplx> &a, double\
\ dir) {\n int i = 0;\n for (int j = 1; j < N - 1; j++) {\n for (int\
\ k = N >> 1; k > (i ^= k); k >>= 1)\n ;\n if (j < i) std::swap(a[i],\
\ a[j]);\n }\n\n std::vector<cmplx> zeta_pow(N);\n for (int i = 0; i\
\ < N; i++) {\n double theta = M_PI / N * i * dir;\n zeta_pow[i]\
\ = {cos(theta), sin(theta)};\n }\n\n for (int m = 1; m < N; m *= 2) {\n\
\ for (int y = 0; y < m; y++) {\n cmplx fac = zeta_pow[N / m\
\ * y];\n for (int x = 0; x < N; x += 2 * m) {\n int\
\ u = x + y;\n int v = x + y + m;\n cmplx s = a[u]\
\ + fac * a[v];\n cmplx t = a[u] - fac * a[v];\n \
\ a[u] = s;\n a[v] = t;\n }\n }\n }\n}\n\
template <typename T>\nstd::vector<cmplx> conv_cmplx(const std::vector<T> &a,\
\ const std::vector<T> &b) {\n int N = 1;\n while (N < (int)a.size() + (int)b.size())\
\ N *= 2;\n std::vector<cmplx> a_(N), b_(N);\n for (int i = 0; i < (int)a.size();\
\ k = N >> 1; k > (i ^= k); k >>= 1) {}\n if (j < i) std::swap(a[i], a[j]);\n\
\ }\n\n std::vector<cmplx> zeta_pow(N);\n for (int i = 0; i < N; i++)\
\ {\n double theta = M_PI / N * i * dir;\n zeta_pow[i] = {cos(theta),\
\ sin(theta)};\n }\n\n for (int m = 1; m < N; m *= 2) {\n for (int\
\ y = 0; y < m; y++) {\n cmplx fac = zeta_pow[N / m * y];\n \
\ for (int x = 0; x < N; x += 2 * m) {\n int u = x + y;\n \
\ int v = x + y + m;\n cmplx s = a[u] + fac * a[v];\n\
\ cmplx t = a[u] - fac * a[v];\n a[u] = s;\n \
\ a[v] = t;\n }\n }\n }\n}\ntemplate <typename\
\ T>\nstd::vector<cmplx> conv_cmplx(const std::vector<T> &a, const std::vector<T>\
\ &b) {\n int N = 1;\n while (N < (int)a.size() + (int)b.size()) N *= 2;\n\
\ std::vector<cmplx> a_(N), b_(N);\n for (int i = 0; i < (int)a.size();\
\ i++) a_[i] = a[i];\n for (int i = 0; i < (int)b.size(); i++) b_[i] = b[i];\n\
\ fft(N, a_, 1);\n fft(N, b_, 1);\n for (int i = 0; i < N; i++) a_[i]\
\ *= b_[i];\n fft(N, a_, -1);\n for (int i = 0; i < N; i++) a_[i] /= N;\n\
Expand All @@ -41,23 +41,22 @@ data:
\ for (int i = 0; i < (int)ans.size(); i++) ret[i] = floor(ans[i].real() + 0.5);\n\
\ ret.resize(a.size() + b.size() - 1);\n return ret;\n}\n"
code: "#pragma once\n#include <complex>\n#include <utility>\n#include <vector>\n\
\n// CUT begin\n// Convolution by FFT (Fast Fourier Transform)\n// Algorithm based\
\ on http://kirika-comp.hatenablog.com/entry/2018/03/12/210446\n// Verified: ATC001C\
\ (168 ms) https://atcoder.jp/contests/atc001/submissions/9243440\nusing cmplx\
\ = std::complex<double>;\nvoid fft(int N, std::vector<cmplx> &a, double dir)\
\ {\n int i = 0;\n for (int j = 1; j < N - 1; j++) {\n for (int k\
\ = N >> 1; k > (i ^= k); k >>= 1)\n ;\n if (j < i) std::swap(a[i],\
\ a[j]);\n }\n\n std::vector<cmplx> zeta_pow(N);\n for (int i = 0; i\
\ < N; i++) {\n double theta = M_PI / N * i * dir;\n zeta_pow[i]\
\ = {cos(theta), sin(theta)};\n }\n\n for (int m = 1; m < N; m *= 2) {\n\
\ for (int y = 0; y < m; y++) {\n cmplx fac = zeta_pow[N / m\
\ * y];\n for (int x = 0; x < N; x += 2 * m) {\n int\
\ u = x + y;\n int v = x + y + m;\n cmplx s = a[u]\
\ + fac * a[v];\n cmplx t = a[u] - fac * a[v];\n \
\ a[u] = s;\n a[v] = t;\n }\n }\n }\n}\n\
template <typename T>\nstd::vector<cmplx> conv_cmplx(const std::vector<T> &a,\
\ const std::vector<T> &b) {\n int N = 1;\n while (N < (int)a.size() + (int)b.size())\
\ N *= 2;\n std::vector<cmplx> a_(N), b_(N);\n for (int i = 0; i < (int)a.size();\
\n// Convolution by FFT (Fast Fourier Transform)\n// Algorithm based on http://kirika-comp.hatenablog.com/entry/2018/03/12/210446\n\
// Verified: ATC001C (168 ms) https://atcoder.jp/contests/atc001/submissions/9243440\n\
using cmplx = std::complex<double>;\nvoid fft(int N, std::vector<cmplx> &a, double\
\ dir) {\n int i = 0;\n for (int j = 1; j < N - 1; j++) {\n for (int\
\ k = N >> 1; k > (i ^= k); k >>= 1) {}\n if (j < i) std::swap(a[i], a[j]);\n\
\ }\n\n std::vector<cmplx> zeta_pow(N);\n for (int i = 0; i < N; i++)\
\ {\n double theta = M_PI / N * i * dir;\n zeta_pow[i] = {cos(theta),\
\ sin(theta)};\n }\n\n for (int m = 1; m < N; m *= 2) {\n for (int\
\ y = 0; y < m; y++) {\n cmplx fac = zeta_pow[N / m * y];\n \
\ for (int x = 0; x < N; x += 2 * m) {\n int u = x + y;\n \
\ int v = x + y + m;\n cmplx s = a[u] + fac * a[v];\n\
\ cmplx t = a[u] - fac * a[v];\n a[u] = s;\n \
\ a[v] = t;\n }\n }\n }\n}\ntemplate <typename\
\ T>\nstd::vector<cmplx> conv_cmplx(const std::vector<T> &a, const std::vector<T>\
\ &b) {\n int N = 1;\n while (N < (int)a.size() + (int)b.size()) N *= 2;\n\
\ std::vector<cmplx> a_(N), b_(N);\n for (int i = 0; i < (int)a.size();\
\ i++) a_[i] = a[i];\n for (int i = 0; i < (int)b.size(); i++) b_[i] = b[i];\n\
\ fft(N, a_, 1);\n fft(N, b_, 1);\n for (int i = 0; i < N; i++) a_[i]\
\ *= b_[i];\n fft(N, a_, -1);\n for (int i = 0; i < N; i++) a_[i] /= N;\n\
Expand All @@ -71,7 +70,7 @@ data:
isVerificationFile: false
path: convolution/fft_double.hpp
requiredBy: []
timestamp: '2022-01-08 20:23:44+09:00'
timestamp: '2024-09-22 15:59:27+09:00'
verificationStatus: LIBRARY_ALL_AC
verifiedWith:
- tree/test/frequency_table_of_tree_distance.test.cpp
Expand Down
40 changes: 19 additions & 21 deletions convolution/hadamard.hpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ data:
- https://codeforces.com/blog/entry/71899>
- https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>
bundledCode: "#line 2 \"convolution/hadamard.hpp\"\n#include <cassert>\n#include\
\ <vector>\n\n// CUT begin\n// Fast Walsh-Hadamard transform and its abstraction\n\
// Tutorials: <https://codeforces.com/blog/entry/71899>\n// <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n\
\ <vector>\n\n// Fast Walsh-Hadamard transform and its abstraction\n// Tutorials:\
\ <https://codeforces.com/blog/entry/71899>\n// <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n\
template <typename T, typename F> void abstract_fwht(std::vector<T> &seq, F f)\
\ {\n const int n = seq.size();\n assert(__builtin_popcount(n) == 1);\n\
\ for (int w = 1; w < n; w *= 2) {\n for (int i = 0; i < n; i += w *\
\ 2) {\n for (int j = 0; j < w; j++) { f(seq[i + j], seq[i + j + w]);\
\ }\n }\n }\n}\n\ntemplate <typename T, typename F1, typename F2>\n\
\ 2) {\n for (int j = 0; j < w; j++) f(seq.at(i + j), seq.at(i + j\
\ + w));\n }\n }\n}\n\ntemplate <typename T, typename F1, typename F2>\n\
std::vector<T> bitwise_conv(std::vector<T> x, std::vector<T> y, F1 f, F2 finv)\
\ {\n const int n = x.size();\n assert(__builtin_popcount(n) == 1);\n \
\ assert(x.size() == y.size());\n if (x == y) {\n abstract_fwht(x,\
\ f), y = x;\n } else {\n abstract_fwht(x, f), abstract_fwht(y, f);\n\
\ }\n for (size_t i = 0; i < x.size(); i++) { x[i] *= y[i]; }\n abstract_fwht(x,\
\ }\n for (int i = 0; i < (int)x.size(); i++) x.at(i) *= y.at(i);\n abstract_fwht(x,\
\ finv);\n return x;\n}\n\n// bitwise xor convolution (FWHT-based)\n// ret[i]\
\ = \\sum_j x[j] * y[i ^ j]\n// if T is integer, ||x||_1 * ||y||_1 * 2 < numeric_limits<T>::max()\n\
template <typename T> std::vector<T> xorconv(std::vector<T> x, std::vector<T>\
Expand All @@ -41,25 +41,24 @@ data:
\ complexity of division by 2 when T is ModInt\n };\n return bitwise_conv(x,\
\ y, f, finv);\n}\n\n// bitwise AND conolution\n// ret[i] = \\sum_{(j & k) ==\
\ i} x[j] * y[k]\ntemplate <typename T> std::vector<T> andconv(std::vector<T>\
\ x, std::vector<T> y) {\n return bitwise_conv(\n x, y, [](T &lo, T\
\ &hi) { lo += hi; }, [](T &lo, T &hi) { lo -= hi; });\n}\n\n// bitwise OR convolution\n\
\ x, std::vector<T> y) {\n return bitwise_conv(x, y, [](T &lo, T &hi) { lo\
\ += hi; }, [](T &lo, T &hi) { lo -= hi; });\n}\n\n// bitwise OR convolution\n\
// ret[i] = \\sum_{(j | k) == i} x[j] * y[k]\ntemplate <typename T> std::vector<T>\
\ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(\n \
\ x, y, [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n\
}\n"
code: "#pragma once\n#include <cassert>\n#include <vector>\n\n// CUT begin\n// Fast\
\ Walsh-Hadamard transform and its abstraction\n// Tutorials: <https://codeforces.com/blog/entry/71899>\n\
\ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(x, y,\
\ [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n}\n"
code: "#pragma once\n#include <cassert>\n#include <vector>\n\n// Fast Walsh-Hadamard\
\ transform and its abstraction\n// Tutorials: <https://codeforces.com/blog/entry/71899>\n\
// <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n\
template <typename T, typename F> void abstract_fwht(std::vector<T> &seq, F f)\
\ {\n const int n = seq.size();\n assert(__builtin_popcount(n) == 1);\n\
\ for (int w = 1; w < n; w *= 2) {\n for (int i = 0; i < n; i += w *\
\ 2) {\n for (int j = 0; j < w; j++) { f(seq[i + j], seq[i + j + w]);\
\ }\n }\n }\n}\n\ntemplate <typename T, typename F1, typename F2>\n\
\ 2) {\n for (int j = 0; j < w; j++) f(seq.at(i + j), seq.at(i + j\
\ + w));\n }\n }\n}\n\ntemplate <typename T, typename F1, typename F2>\n\
std::vector<T> bitwise_conv(std::vector<T> x, std::vector<T> y, F1 f, F2 finv)\
\ {\n const int n = x.size();\n assert(__builtin_popcount(n) == 1);\n \
\ assert(x.size() == y.size());\n if (x == y) {\n abstract_fwht(x,\
\ f), y = x;\n } else {\n abstract_fwht(x, f), abstract_fwht(y, f);\n\
\ }\n for (size_t i = 0; i < x.size(); i++) { x[i] *= y[i]; }\n abstract_fwht(x,\
\ }\n for (int i = 0; i < (int)x.size(); i++) x.at(i) *= y.at(i);\n abstract_fwht(x,\
\ finv);\n return x;\n}\n\n// bitwise xor convolution (FWHT-based)\n// ret[i]\
\ = \\sum_j x[j] * y[i ^ j]\n// if T is integer, ||x||_1 * ||y||_1 * 2 < numeric_limits<T>::max()\n\
template <typename T> std::vector<T> xorconv(std::vector<T> x, std::vector<T>\
Expand All @@ -69,17 +68,16 @@ data:
\ complexity of division by 2 when T is ModInt\n };\n return bitwise_conv(x,\
\ y, f, finv);\n}\n\n// bitwise AND conolution\n// ret[i] = \\sum_{(j & k) ==\
\ i} x[j] * y[k]\ntemplate <typename T> std::vector<T> andconv(std::vector<T>\
\ x, std::vector<T> y) {\n return bitwise_conv(\n x, y, [](T &lo, T\
\ &hi) { lo += hi; }, [](T &lo, T &hi) { lo -= hi; });\n}\n\n// bitwise OR convolution\n\
\ x, std::vector<T> y) {\n return bitwise_conv(x, y, [](T &lo, T &hi) { lo\
\ += hi; }, [](T &lo, T &hi) { lo -= hi; });\n}\n\n// bitwise OR convolution\n\
// ret[i] = \\sum_{(j | k) == i} x[j] * y[k]\ntemplate <typename T> std::vector<T>\
\ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(\n \
\ x, y, [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n\
}\n"
\ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(x, y,\
\ [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n}\n"
dependsOn: []
isVerificationFile: false
path: convolution/hadamard.hpp
requiredBy: []
timestamp: '2022-01-08 20:23:44+09:00'
timestamp: '2024-09-22 16:07:49+09:00'
verificationStatus: LIBRARY_ALL_AC
verifiedWith:
- convolution/test/bitwise_xor_conv.test.cpp
Expand Down
26 changes: 13 additions & 13 deletions convolution/test/bitwise_and_conv.test.cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ data:
\ ModInt<md>::facinvs = {1};\ntemplate <int md> std::vector<ModInt<md>> ModInt<md>::invs\
\ = {0};\n\nusing ModInt998244353 = ModInt<998244353>;\n// using mint = ModInt<998244353>;\n\
// using mint = ModInt<1000000007>;\n#line 4 \"convolution/hadamard.hpp\"\n\n\
// CUT begin\n// Fast Walsh-Hadamard transform and its abstraction\n// Tutorials:\
\ <https://codeforces.com/blog/entry/71899>\n// <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n\
// Fast Walsh-Hadamard transform and its abstraction\n// Tutorials: <https://codeforces.com/blog/entry/71899>\n\
// <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n\
template <typename T, typename F> void abstract_fwht(std::vector<T> &seq, F f)\
\ {\n const int n = seq.size();\n assert(__builtin_popcount(n) == 1);\n\
\ for (int w = 1; w < n; w *= 2) {\n for (int i = 0; i < n; i += w *\
\ 2) {\n for (int j = 0; j < w; j++) { f(seq[i + j], seq[i + j + w]);\
\ }\n }\n }\n}\n\ntemplate <typename T, typename F1, typename F2>\n\
\ 2) {\n for (int j = 0; j < w; j++) f(seq.at(i + j), seq.at(i + j\
\ + w));\n }\n }\n}\n\ntemplate <typename T, typename F1, typename F2>\n\
std::vector<T> bitwise_conv(std::vector<T> x, std::vector<T> y, F1 f, F2 finv)\
\ {\n const int n = x.size();\n assert(__builtin_popcount(n) == 1);\n \
\ assert(x.size() == y.size());\n if (x == y) {\n abstract_fwht(x,\
\ f), y = x;\n } else {\n abstract_fwht(x, f), abstract_fwht(y, f);\n\
\ }\n for (size_t i = 0; i < x.size(); i++) { x[i] *= y[i]; }\n abstract_fwht(x,\
\ }\n for (int i = 0; i < (int)x.size(); i++) x.at(i) *= y.at(i);\n abstract_fwht(x,\
\ finv);\n return x;\n}\n\n// bitwise xor convolution (FWHT-based)\n// ret[i]\
\ = \\sum_j x[j] * y[i ^ j]\n// if T is integer, ||x||_1 * ||y||_1 * 2 < numeric_limits<T>::max()\n\
template <typename T> std::vector<T> xorconv(std::vector<T> x, std::vector<T>\
Expand All @@ -133,14 +133,14 @@ data:
\ complexity of division by 2 when T is ModInt\n };\n return bitwise_conv(x,\
\ y, f, finv);\n}\n\n// bitwise AND conolution\n// ret[i] = \\sum_{(j & k) ==\
\ i} x[j] * y[k]\ntemplate <typename T> std::vector<T> andconv(std::vector<T>\
\ x, std::vector<T> y) {\n return bitwise_conv(\n x, y, [](T &lo, T\
\ &hi) { lo += hi; }, [](T &lo, T &hi) { lo -= hi; });\n}\n\n// bitwise OR convolution\n\
\ x, std::vector<T> y) {\n return bitwise_conv(x, y, [](T &lo, T &hi) { lo\
\ += hi; }, [](T &lo, T &hi) { lo -= hi; });\n}\n\n// bitwise OR convolution\n\
// ret[i] = \\sum_{(j | k) == i} x[j] * y[k]\ntemplate <typename T> std::vector<T>\
\ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(\n \
\ x, y, [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n\
}\n#line 5 \"convolution/test/bitwise_and_conv.test.cpp\"\nusing namespace std;\n\
\nint main() {\n cin.tie(nullptr), ios::sync_with_stdio(false);\n int N;\n\
\ cin >> N;\n vector<ModInt<998244353>> A(1 << N), B(1 << N);\n for (auto\
\ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(x, y,\
\ [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n}\n#line 5\
\ \"convolution/test/bitwise_and_conv.test.cpp\"\nusing namespace std;\n\nint\
\ main() {\n cin.tie(nullptr), ios::sync_with_stdio(false);\n int N;\n \
\ cin >> N;\n vector<ModInt<998244353>> A(1 << N), B(1 << N);\n for (auto\
\ &x : A) cin >> x;\n for (auto &x : B) cin >> x;\n\n for (auto x : andconv(A,\
\ B)) cout << x << ' ';\n}\n"
code: "#define PROBLEM \"https://judge.yosupo.jp/problem/bitwise_and_convolution\"\
Expand All @@ -155,7 +155,7 @@ data:
isVerificationFile: true
path: convolution/test/bitwise_and_conv.test.cpp
requiredBy: []
timestamp: '2023-12-26 21:26:22+09:00'
timestamp: '2024-09-22 16:07:49+09:00'
verificationStatus: TEST_ACCEPTED
verifiedWith: []
documentation_of: convolution/test/bitwise_and_conv.test.cpp
Expand Down
Loading

0 comments on commit 03628bb

Please sign in to comment.