cpp-library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub shino16/cpp-library

:heavy_check_mark: poset/set.hpp

Depends on

Verified with

Code

#pragma once

#include "bit/ctz.hpp"

template <class T>
void zeta(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j + h] += v[j];
}

template <class T>
void zeta_r(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j] += v[j + h];
}

template <class T>
void moebius(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j + h] -= v[j];
}

template <class T>
void moebius_r(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j] -= v[j + h];
}

namespace atcoder::internal {
struct modint_base;
}

template <class T>
void hadamard(vector<T>& v, bool inv = false) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) tie(v[j], v[j + h]) =
          pair(v[j] + v[j + h], v[j] - v[j + h]);
  if (inv) {
    if constexpr (is_base_of_v<atcoder::internal::modint_base, T>) {
      T c = T(v.size()).inv();
      rep(i, v.size()) v[i] *= c;
    } else {
      int n = ctz(v.size());
      rep(i, v.size()) v[i] >>= n;
    }
  }
}
#line 2 "poset/set.hpp"

#line 2 "prelude.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vc = vector<char>;
#define rep2(i, m, n) for (auto i = (m); i < (n); i++)
#define rep(i, n) rep2(i, 0, n)
#define repr2(i, m, n) for (auto i = (n); i-- > (m);)
#define repr(i, n) repr2(i, 0, n)
#define all(x) begin(x), end(x)
auto ndvec(int n, auto e) { return vector(n, e); }
auto ndvec(int n, auto ...e) { return vector(n, ndvec(e...)); }
auto comp_key(auto&& f) { return [&](auto&& a, auto&& b) { return f(a) < f(b); }; }
auto& max(const auto& a, const auto& b) { return a < b ? b : a; }
auto& min(const auto& a, const auto& b) { return b < a ? b : a; }
#if __cpp_lib_ranges
namespace R = std::ranges;
namespace V = std::views;
#endif
#line 3 "bit/ctz.hpp"

#pragma GCC target("bmi")

template <class T>
int ctz(T x) {
  if (!x) return sizeof(T) * 8;
  if constexpr (sizeof(T) <= sizeof(unsigned)) {
    return __builtin_ctz((unsigned)x);
  } else if constexpr (sizeof(T) <= sizeof(unsigned long long)) {
    return __builtin_ctzll((unsigned long long)x);
  } else if constexpr (sizeof(T) <= sizeof(unsigned long long) * 2) {
    unsigned long long y = x;
    return y ? ctz(y)
             : sizeof(y) * 8 + ctz((unsigned long long)(x >> sizeof(y) * 8));
  }
}
#line 4 "poset/set.hpp"

template <class T>
void zeta(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j + h] += v[j];
}

template <class T>
void zeta_r(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j] += v[j + h];
}

template <class T>
void moebius(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j + h] -= v[j];
}

template <class T>
void moebius_r(vector<T>& v) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) v[j] -= v[j + h];
}

namespace atcoder::internal {
struct modint_base;
}

template <class T>
void hadamard(vector<T>& v, bool inv = false) {
  for (int h = 1; h < v.size(); h <<= 1)
    for (int i = 0; i < v.size(); i += h * 2)
      rep2(j, i, i + h) tie(v[j], v[j + h]) =
          pair(v[j] + v[j + h], v[j] - v[j + h]);
  if (inv) {
    if constexpr (is_base_of_v<atcoder::internal::modint_base, T>) {
      T c = T(v.size()).inv();
      rep(i, v.size()) v[i] *= c;
    } else {
      int n = ctz(v.size());
      rep(i, v.size()) v[i] >>= n;
    }
  }
}
Back to top page