This documentation is automatically generated by online-judge-tools/verification-helper
#include "set_function/hadamard_transform.hpp"
アダマール変換を行う。 $O(N\log N)$
#pragma once
#include <vector>
namespace ebi {
template <class T>
std::vector<T> hadamard_transform(std::vector<T> f, bool inverse = false) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((i & j) == 0) {
T x = f[j], y = f[j | i];
f[j] = x + y;
f[j | i] = x - y;
}
}
}
if (inverse) {
for (auto& x : f) {
x /= T(n);
}
}
return f;
}
} // namespace ebi
#line 2 "set_function/hadamard_transform.hpp"
#include <vector>
namespace ebi {
template <class T>
std::vector<T> hadamard_transform(std::vector<T> f, bool inverse = false) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((i & j) == 0) {
T x = f[j], y = f[j | i];
f[j] = x + y;
f[j | i] = x - y;
}
}
}
if (inverse) {
for (auto& x : f) {
x /= T(n);
}
}
return f;
}
} // namespace ebi