library

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

View the Project on GitHub maspypy/library

:heavy_check_mark: setfunc/or_convolution.hpp

Depends on

Verified with

Code

#include "setfunc/zeta.hpp"

template <typename T>
vc<T> or_convolution(vc<T> A, vc<T> B) {
  subset_zeta(A);
  subset_zeta(B);
  FOR(i, len(A)) A[i] *= B[i];
  subset_mobius(A);
  return A;
}
#line 2 "setfunc/zeta.hpp"

template <typename T>
void superset_zeta(vc<T>& A) {
  int log = topbit(len(A));
  assert(1 << log == len(A));
  FOR(n, log) FOR(s, 1 << log) {
    int t = s ^ (1 << n);
    if (s < t) A[s] += A[t];
  }
}

template <typename T>
void superset_mobius(vc<T>& A) {
  int log = topbit(len(A));
  assert(1 << log == len(A));
  FOR(n, log) FOR(s, 1 << log) {
    int t = s ^ (1 << n);
    if (s < t) A[s] -= A[t];
  }
}

template <typename T>
void subset_zeta(vc<T>& A) {
  int log = topbit(len(A));
  assert(1 << log == len(A));
  FOR(n, log) FOR(s, 1 << log) {
    int t = s ^ (1 << n);
    if (s > t) A[s] += A[t];
  }
}

template <typename T>
void subset_mobius(vc<T>& A) {
  int log = topbit(len(A));
  assert(1 << log == len(A));
  FOR(n, log) FOR(s, 1 << log) {
    int t = s ^ (1 << n);
    if (s > t) A[s] -= A[t];
  }
}
#line 2 "setfunc/or_convolution.hpp"
template <typename T>
vc<T> or_convolution(vc<T> A, vc<T> B) {
  subset_zeta(A);
  subset_zeta(B);
  FOR(i, len(A)) A[i] *= B[i];
  subset_mobius(A);
  return A;
}
Back to top page