kyopro-lib

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

View on GitHub

:x: Convolution (Index bitwise OR)
(Mylib/Convolution/convolution_or.cpp)

Operations

Requirements

Notes

Problems

References

Depends on

Verified with

Code

#pragma once
#include <vector>
#include "Mylib/Convolution/fast_mobius_transform_subset.cpp"
#include "Mylib/Convolution/fast_zeta_transform_subset.cpp"

namespace haar_lib {
  template <typename T>
  std::vector<T> convolution_or(std::vector<T> f, std::vector<T> g) {
    f = fast_zeta_transform_subset(f);
    g = fast_zeta_transform_subset(g);
    for (size_t i = 0; i < f.size(); ++i) f[i] *= g[i];
    f = fast_mobius_transform_subset(f);
    return f;
  }
}  // namespace haar_lib
#line 2 "Mylib/Convolution/convolution_or.cpp"
#include <vector>
#line 2 "Mylib/Convolution/fast_mobius_transform_subset.cpp"
#include <cassert>
#include <functional>
#line 5 "Mylib/Convolution/fast_mobius_transform_subset.cpp"

namespace haar_lib {
  template <typename T, typename Func = std::minus<T>>
  std::vector<T> fast_mobius_transform_subset(std::vector<T> f, const Func &op = std::minus<T>()) {
    const int N = f.size();
    assert((N & (N - 1)) == 0 && "N must be a power of 2");
    for (int i = 1; i < N; i <<= 1) {
      for (int j = 0; j < N; ++j) {
        if (j & i) f[j] = op(f[j], f[j ^ i]);
      }
    }
    return f;
  }
}  // namespace haar_lib
#line 5 "Mylib/Convolution/fast_zeta_transform_subset.cpp"

namespace haar_lib {
  template <typename T, typename Func = std::plus<T>>
  std::vector<T> fast_zeta_transform_subset(std::vector<T> f, const Func &op = std::plus<T>()) {
    const int N = f.size();
    assert((N & (N - 1)) == 0 && "N must be a power of 2");
    for (int i = 1; i < N; i <<= 1) {
      for (int j = 0; j < N; ++j) {
        if (j & i) f[j] = op(f[j], f[j ^ i]);
      }
    }
    return f;
  }
}  // namespace haar_lib
#line 5 "Mylib/Convolution/convolution_or.cpp"

namespace haar_lib {
  template <typename T>
  std::vector<T> convolution_or(std::vector<T> f, std::vector<T> g) {
    f = fast_zeta_transform_subset(f);
    g = fast_zeta_transform_subset(g);
    for (size_t i = 0; i < f.size(); ++i) f[i] *= g[i];
    f = fast_mobius_transform_subset(f);
    return f;
  }
}  // namespace haar_lib
Back to top page