1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <bits/stdc++.h> using namespace std; using LL = long long; #define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i) #ifdef zerol #define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0) void err() { cout << "\033[39;0m" << endl; } template<template<typename...> class T, typename t, typename... A> void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); } template<typename T, typename... A> void err(T a, A... x) { cout << a << ' '; err(x...); } #else #define dbg(...) #endif // ----------------------------------------------------------------------------- const int N = 1 << 24; LL A[N]; LL B[N]; LL k, _n, n;
LL f(LL x) { LL ret = 0, c = 1; while (x) { ret += c * (x % 3); x /= 3; c *= 4; } return ret; }
template<typename T> void fwt(LL a[N], LL n, T f) { for (LL d = 1; d < n; d *= 4) for (LL i = 0, t = d * 4; i < n; i += t) FOR (j, 0, d) f(a[i + j], a[i + j + d], a[i + j + 2 * d], a[i + j + 3 * d]); }
void go(LL& a, LL& b, LL& c, LL& d) { LL x0 = a, x1 = b, x2 = c, x3 = d; a = x1 + x2; b = x0 + x1 + x2; c = x0 + x2; d = x2; }
void rgo(LL& a, LL& b, LL& c, LL& d) { LL x0 = a, x1 = b, x2 = c, x3 = d; a = x0; b = x2 - x3; c = x1 - x0 - x2 + x3; }
int main() { cin >> k; _n = n = 1; FOR (_, 0, k) { _n *= 3; n *= 4; } FOR (i, 0, _n) scanf("%lld", &A[f(i)]); FOR (i, 0, _n) scanf("%lld", &B[f(i)]); fwt(A, n, go); fwt(B, n, go); FOR (i, 0, n) A[i] = A[i] * B[i]; fwt(A, n, rgo); FOR (i, 0, _n) { printf("%lld%c", A[f(i)], i == _i - 1 ? '\n' : ' '); } }
|