前言
没有前言
讲解
暂时不打算讲解
放一个巨佬的博客供膜拜
再来一个外校的巨佬
练习
代码
板题代码
//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
#define TT template<typename T>
using namespace std;
typedef long long LL;
const int MAXN = 1 << 17 | 5;
const int MOD = 998244353;
const int inv2 = 499122177;
int n,N;
int a[MAXN],b[MAXN],a1[MAXN],b1[MAXN];
LL Read()
{
LL x = 0,f = 1;char c = getchar();
while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
return x * f;
}
TT void Put1(T x)
{
if(x > 9) Put1(x/10);
putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
if(x < 0) putchar('-'),x = -x;
Put1(x);
if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}
int qpow(int x,int y)
{
int ret = 1;
while(y){if(y & 1) ret = 1ll * ret * x % MOD;x = 1ll * x * x % MOD;y >>= 1;}
return ret;
}
void Add(int &x){if(x >= MOD) x -= MOD;}
void Del(int &x){if(x < 0) x += MOD;}
void fwtor(int *a,int opt)
{
for(int i = 1;i < N;i <<= 1)//块长
for(int p = i << 1,j = 0;j < N;j += p)//第几个块
for(int k = 0;k < i;++ k)//块内第几个
if(opt == 1) Add(a[i+j+k] += a[j+k]);
else Del(a[i+j+k] -= a[j+k]);
}
void fwtand(int *a,int opt)
{
for(int i = 1;i < N;i <<= 1)//块长
for(int p = i << 1,j = 0;j < N;j += p)//第几个块
for(int k = 0;k < i;++ k)//块内第几个
if(opt == 1) Add(a[j+k] += a[i+j+k]);
else Del(a[j+k] -= a[i+j+k]);
}
void fwtxor(int *a,int opt)
{
for(int i = 1;i < N;i <<= 1)//块长
for(int p = i << 1,j = 0;j < N;j += p)//第几个块
for(int k = 0;k < i;++ k)//块内第几个
{
int x = a[j+k],y = a[i+j+k];
if(opt == 1) Add(a[j+k] = x+y),Del(a[i+j+k] = x-y);
else a[j+k] = 1ll * (x + y) * inv2 % MOD,a[i+j+k] = 1ll * (x - y) * inv2 % MOD;
}
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n = Read(); N = 1 << n;
for(int i = 0;i < N;++ i) a[i] = Read();
for(int i = 0;i < N;++ i) b[i] = Read();
//or
for(int i = 0;i < N;++ i) a1[i] = a[i],b1[i] = b[i];
fwtor(a1,1);
fwtor(b1,1);
for(int i = 0;i < N;++ i) a1[i] = 1ll * a1[i] * b1[i] % MOD;
fwtor(a1,-1);
for(int i = 0;i < N;++ i) Del(a1[i]),Put(a1[i],i == N - 1 ? '
' : ' ');
//and
for(int i = 0;i < N;++ i) a1[i] = a[i],b1[i] = b[i];
fwtand(a1,1);
fwtand(b1,1);
for(int i = 0;i < N;++ i) a1[i] = 1ll * a1[i] * b1[i] % MOD;
fwtand(a1,-1);
for(int i = 0;i < N;++ i) Del(a1[i]),Put(a1[i],i == N - 1 ? '
' : ' ');
//xor
fwtxor(a,1);
fwtxor(b,1);
for(int i = 0;i < N;++ i) a[i] = 1ll * a[i] * b[i] % MOD;
fwtxor(a,-1);
for(int i = 0;i < N;++ i) Del(a[i]),Put(a[i],i == N - 1 ? '
' : ' ');
return 0;
}