@@ -20,18 +20,18 @@ data:
20
20
- https://codeforces.com/blog/entry/71899>
21
21
- https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>
22
22
bundledCode : " #line 2 \" convolution/hadamard.hpp\"\n #include <cassert>\n #include\
23
- \ <vector>\n\n // CUT begin \n // Fast Walsh-Hadamard transform and its abstraction\n \
24
- // Tutorials: <https://codeforces.com/blog/entry/71899>\n // <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n \
23
+ \ <vector>\n\n // Fast Walsh-Hadamard transform and its abstraction\n // Tutorials: \
24
+ \ <https://codeforces.com/blog/entry/71899>\n // <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n \
25
25
template <typename T, typename F> void abstract_fwht(std::vector<T> &seq, F f)\
26
26
\ {\n const int n = seq.size();\n assert(__builtin_popcount(n) == 1);\n \
27
27
\ for (int w = 1; w < n; w *= 2) {\n for (int i = 0; i < n; i += w *\
28
- \ 2) {\n for (int j = 0; j < w; j++) { f(seq[ i + j] , seq[ i + j + w]); \
29
- \ } \n }\n }\n }\n\n template <typename T, typename F1, typename F2>\n \
28
+ \ 2) {\n for (int j = 0; j < w; j++) f(seq.at( i + j) , seq.at( i + j\
29
+ \ + w)); \n }\n }\n }\n\n template <typename T, typename F1, typename F2>\n \
30
30
std::vector<T> bitwise_conv(std::vector<T> x, std::vector<T> y, F1 f, F2 finv)\
31
31
\ {\n const int n = x.size();\n assert(__builtin_popcount(n) == 1);\n \
32
32
\ assert(x.size() == y.size());\n if (x == y) {\n abstract_fwht(x,\
33
33
\ f), y = x;\n } else {\n abstract_fwht(x, f), abstract_fwht(y, f);\n \
34
- \ }\n for (size_t i = 0; i < x.size(); i++) { x[i] *= y[i]; } \n abstract_fwht(x,\
34
+ \ }\n for (int i = 0; i < (int) x.size(); i++) x.at(i) *= y.at(i); \n abstract_fwht(x,\
35
35
\ finv);\n return x;\n }\n\n // bitwise xor convolution (FWHT-based)\n // ret[i]\
36
36
\ = \\ sum_j x[j] * y[i ^ j]\n // if T is integer, ||x||_1 * ||y||_1 * 2 < numeric_limits<T>::max()\n \
37
37
template <typename T> std::vector<T> xorconv(std::vector<T> x, std::vector<T>\
@@ -41,25 +41,24 @@ data:
41
41
\ complexity of division by 2 when T is ModInt\n };\n return bitwise_conv(x,\
42
42
\ y, f, finv);\n }\n\n // bitwise AND conolution\n // ret[i] = \\ sum_{(j & k) ==\
43
43
\ i} x[j] * y[k]\n template <typename T> std::vector<T> andconv(std::vector<T>\
44
- \ x, std::vector<T> y) {\n return bitwise_conv(\n x, y, [](T &lo, T\
45
- \ &hi) { lo += hi; }, [](T &lo, T &hi) { lo -= hi; });\n }\n\n // bitwise OR convolution\n \
44
+ \ x, std::vector<T> y) {\n return bitwise_conv(x, y, [](T &lo, T &hi) { lo \
45
+ \ += hi; }, [](T &lo, T &hi) { lo -= hi; });\n }\n\n // bitwise OR convolution\n \
46
46
// ret[i] = \\ sum_{(j | k) == i} x[j] * y[k]\n template <typename T> std::vector<T>\
47
- \ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(\n \
48
- \ x, y, [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n \
49
- }\n "
50
- code : " #pragma once\n #include <cassert>\n #include <vector>\n\n // CUT begin\n // Fast\
51
- \ Walsh-Hadamard transform and its abstraction\n // Tutorials: <https://codeforces.com/blog/entry/71899>\n \
47
+ \ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(x, y,\
48
+ \ [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n }\n "
49
+ code : " #pragma once\n #include <cassert>\n #include <vector>\n\n // Fast Walsh-Hadamard\
50
+ \ transform and its abstraction\n // Tutorials: <https://codeforces.com/blog/entry/71899>\n \
52
51
// <https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it>\n \
53
52
template <typename T, typename F> void abstract_fwht(std::vector<T> &seq, F f)\
54
53
\ {\n const int n = seq.size();\n assert(__builtin_popcount(n) == 1);\n \
55
54
\ for (int w = 1; w < n; w *= 2) {\n for (int i = 0; i < n; i += w *\
56
- \ 2) {\n for (int j = 0; j < w; j++) { f(seq[ i + j] , seq[ i + j + w]); \
57
- \ } \n }\n }\n }\n\n template <typename T, typename F1, typename F2>\n \
55
+ \ 2) {\n for (int j = 0; j < w; j++) f(seq.at( i + j) , seq.at( i + j\
56
+ \ + w)); \n }\n }\n }\n\n template <typename T, typename F1, typename F2>\n \
58
57
std::vector<T> bitwise_conv(std::vector<T> x, std::vector<T> y, F1 f, F2 finv)\
59
58
\ {\n const int n = x.size();\n assert(__builtin_popcount(n) == 1);\n \
60
59
\ assert(x.size() == y.size());\n if (x == y) {\n abstract_fwht(x,\
61
60
\ f), y = x;\n } else {\n abstract_fwht(x, f), abstract_fwht(y, f);\n \
62
- \ }\n for (size_t i = 0; i < x.size(); i++) { x[i] *= y[i]; } \n abstract_fwht(x,\
61
+ \ }\n for (int i = 0; i < (int) x.size(); i++) x.at(i) *= y.at(i); \n abstract_fwht(x,\
63
62
\ finv);\n return x;\n }\n\n // bitwise xor convolution (FWHT-based)\n // ret[i]\
64
63
\ = \\ sum_j x[j] * y[i ^ j]\n // if T is integer, ||x||_1 * ||y||_1 * 2 < numeric_limits<T>::max()\n \
65
64
template <typename T> std::vector<T> xorconv(std::vector<T> x, std::vector<T>\
@@ -69,17 +68,16 @@ data:
69
68
\ complexity of division by 2 when T is ModInt\n };\n return bitwise_conv(x,\
70
69
\ y, f, finv);\n }\n\n // bitwise AND conolution\n // ret[i] = \\ sum_{(j & k) ==\
71
70
\ i} x[j] * y[k]\n template <typename T> std::vector<T> andconv(std::vector<T>\
72
- \ x, std::vector<T> y) {\n return bitwise_conv(\n x, y, [](T &lo, T\
73
- \ &hi) { lo += hi; }, [](T &lo, T &hi) { lo -= hi; });\n }\n\n // bitwise OR convolution\n \
71
+ \ x, std::vector<T> y) {\n return bitwise_conv(x, y, [](T &lo, T &hi) { lo \
72
+ \ += hi; }, [](T &lo, T &hi) { lo -= hi; });\n }\n\n // bitwise OR convolution\n \
74
73
// ret[i] = \\ sum_{(j | k) == i} x[j] * y[k]\n template <typename T> std::vector<T>\
75
- \ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(\n \
76
- \ x, y, [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n \
77
- }\n "
74
+ \ orconv(std::vector<T> x, std::vector<T> y) {\n return bitwise_conv(x, y,\
75
+ \ [](T &lo, T &hi) { hi += lo; }, [](T &lo, T &hi) { hi -= lo; });\n }\n "
78
76
dependsOn : []
79
77
isVerificationFile : false
80
78
path : convolution/hadamard.hpp
81
79
requiredBy : []
82
- timestamp : ' 2022-01-08 20:23:44 +09:00'
80
+ timestamp : ' 2024-09-22 16:07:49 +09:00'
83
81
verificationStatus : LIBRARY_ALL_AC
84
82
verifiedWith :
85
83
- convolution/test/bitwise_xor_conv.test.cpp
0 commit comments