competitive-programing

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

View the Project on GitHub Astral-23/competitive-programing

:heavy_check_mark: verify/bitwise_and_convolution.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/bitwise_and_convolution"
#include "../Utility/template.hpp"
#include "../Utility/modint.hpp"
#include "../Convolution/bitwise_and_convolution.hpp"

using mint = modint998244353;

using S = mint;
S op(S l, S r) {
    return l + r;
}

S inv(S x) {
    return -1 * x;
}

S zero() {
    return 0;
}



int main() {
    int n;
    cin >> n;
    vec<mint> A(1 << n), B(1 << n);
    rep(i, 0, 1 << n) cin >> A[i];
    rep(i, 0, 1 << n) cin >> B[i];

    auto f = bitwise_and_convolution<S, op, inv, zero>(A, B);
    rep(i, 0, 1 << n) cout << f[i] << " ";
    cout << endl;

}
#line 1 "verify/bitwise_and_convolution.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/bitwise_and_convolution"
#line 1 "Utility/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)

#define TT template <typename T>
TT using vec = vector<T>;
template <class T1, class T2> bool chmin(T1 &x, T2 y) {
    return x > y ? (x = y, true) : false;
}
template <class T1, class T2> bool chmax(T1 &x, T2 y) {
    return x < y ? (x = y, true) : false;
}
struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
} io_setup;

/*
@brief verify用テンプレート
*/
#line 1 "Utility/modint.hpp"

// 動的mod : template<int mod> を消して、上の方で変数modを宣言
template <uint32_t mod> struct modint {
    using mm = modint;
    uint32_t x;
    modint() : x(0) {}
    TT modint(T a = 0) : x((ll(a) % mod + mod)) {
        if (x >= mod) x -= mod;
    }

    friend mm operator+(mm a, mm b) {
        a.x += b.x;
        if (a.x >= mod) a.x -= mod;
        return a;
    }
    friend mm operator-(mm a, mm b) {
        a.x -= b.x;
        if (a.x >= mod) a.x += mod;
        return a;
    }

    mm operator-() const { return mod - x; }

    //+と-だけで十分な場合、以下は省略して良いです。

    friend mm operator*(mm a, mm b) { return (uint64_t)(a.x) * b.x; }
    friend mm operator/(mm a, mm b) { return a * b.inv(); }
    friend mm &operator+=(mm &a, mm b) { return a = a + b; }
    friend mm &operator-=(mm &a, mm b) { return a = a - b; }
    friend mm &operator*=(mm &a, mm b) { return a = a * b; }
    friend mm &operator/=(mm &a, mm b) { return a = a * b.inv(); }

    mm inv() const {
        assert(x != 0);
        return pow(mod - 2);
    }
    mm pow(ll y) const {
        mm res = 1;
        mm v = *this;
        while (y) {
            if (y & 1) res *= v;
            v *= v;
            y /= 2;
        }
        return res;
    }

    friend istream &operator>>(istream &is, mm &a) {
        ll t;
        cin >> t;
        a = mm(t);
        return is;
    }

    friend ostream &operator<<(ostream &os, mm a) { return os << a.x; }

    bool operator==(mm a) { return x == a.x; }
    bool operator!=(mm a) { return x != a.x; }

    bool operator<(const mm &a) const { return x < a.x; }
};
using modint998244353 = modint<998244353>;
using modint1000000007 = modint<1'000'000'007>;
/*
@brief modint
*/
#line 1 "Algorithm/superset_transform.hpp"
template<class S, S (*op)(S, S)> vector<S> superset_zeta_transform (vector<S> f, int n) {
    rep(i, 0, n) {
        rep(s, 0, 1LL << n) {
            if((s & (1 << i)) == 0) { // if i in s
                f[s] = op(f[s], f[s ^ (1 << i)]);
            }
        }
    }
    return f;
}

template<class S, S (*op)(S, S), S (*inv)(S)> vector<S> superset_mobius_transform (vector<S> f, int n) {
    rrep(i, 0, n) {
        rep(s, 0, 1LL << n) {
            if((s & (1 << i)) == 0) { // if i in s
                f[s] = op(f[s], inv(f[s ^ (1 << i)]));
                //f[s] = f[s] -  f[s ^ (1 << i)];
            }
        }
    }
    return f;
}
#line 2 "Convolution/bitwise_and_convolution.hpp"
// i and j = k <-> i and j が k の superset (⇔ i, jがともにkのsuperset)
template<class S, S (*op)(S, S), S (*inv)(S),  S(*zero)()> vec<S> bitwise_and_convolution(vec<S> A, vec<S> B) {
    ll lg = 1;
    while(A.size() > (1LL << lg)) lg++;
    while(B.size() > (1LL << lg)) lg++;
    A.resize(1LL << lg, zero());
    B.resize(1LL << lg, zero());

    vec<S> FA = superset_zeta_transform<S, op>(A, lg);
    vec<S> FB = superset_zeta_transform<S, op>(B, lg);
    rep(i, 0, 1 << lg) FA[i] *= FB[i];
    vec<S> f = superset_mobius_transform<S, op, inv>(FA, lg);
    return f;
}
//以降の項について、0である。
#line 5 "verify/bitwise_and_convolution.test.cpp"

using mint = modint998244353;

using S = mint;
S op(S l, S r) {
    return l + r;
}

S inv(S x) {
    return -1 * x;
}

S zero() {
    return 0;
}



int main() {
    int n;
    cin >> n;
    vec<mint> A(1 << n), B(1 << n);
    rep(i, 0, 1 << n) cin >> A[i];
    rep(i, 0, 1 << n) cin >> B[i];

    auto f = bitwise_and_convolution<S, op, inv, zero>(A, B);
    rep(i, 0, 1 << n) cout << f[i] << " ";
    cout << endl;

}
Back to top page