competitive-programming-templates

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Misuki743/competitive-programming-templates

:heavy_check_mark: setfunc/FWHT.cpp

Verified with

Code

template<class Mint>
void FWHT(vector<Mint> &a, bool inverse) {
  for(int n = ssize(a), step = 1; step < n; step <<= 1)
    for(int i = 0; i < n; i += step << 1)
      for(int j = i; j < i + step; j++)
        tie(a[j], a[j + step]) = pair(a[j] + a[j + step], a[j] - a[j + step]);
  if (inverse) {
    Mint I = Mint(1) / Mint(ssize(a));
    for(Mint &x : a) x *= I;
  }
}
#line 1 "setfunc/FWHT.cpp"
template<class Mint>
void FWHT(vector<Mint> &a, bool inverse) {
  for(int n = ssize(a), step = 1; step < n; step <<= 1)
    for(int i = 0; i < n; i += step << 1)
      for(int j = i; j < i + step; j++)
        tie(a[j], a[j + step]) = pair(a[j] + a[j + step], a[j] - a[j + step]);
  if (inverse) {
    Mint I = Mint(1) / Mint(ssize(a));
    for(Mint &x : a) x *= I;
  }
}
Back to top page