Kanade's convolution

题目链接

题意

已知$A$和$B$数列,且

计算

思路

设$i$ $or$ $j = x$,$i$ $xor$ $j = y$.那么$i$ $and$ $j = x$ $xor$ $y$.且要求$x$ $and$ $y = y$.

考虑新的函数表示同理。

则有

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[33;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
#define inf 1ll << 50

const ll mod = 998244353;
const ll inv2 = (998244353 + 1) / 2;
/*
void FWT_or(ll *a, int n, 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 < n; ++k)
if (opt == 1)
a[i + j + k] = a[j + k] + a[i + j + k];
else
a[i + j + k] = a[i + j + k] - a[j + k];
}
void FWT_and(ll *a, int n, 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)
a[j + k] = a[j + k] + a[i + j + k];
else
a[j + k] = a[j + k] - a[i + j + k];
}
*/
void FWT_xor(ll *a, int n, 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)
{
ll X = a[j + k], Y = a[i + j + k];
a[j + k] = (X + Y) % mod;
a[i + j + k] = (X - Y + mod) % mod;
if (opt == -1)
a[j + k] = 1ll * a[j + k] * inv2 % mod, a[i + j + k] = 1ll * a[i + j + k] * inv2 % mod;
}
}

const int N = 1e6 + 5;
ll a[20][N], b[20][N];
ll A[N], B[N];
ll c[20][N];
int main()
{
int m;
scanf("%d", &m);
int up = 1 << m;
for (int i = 0; i < up; i++)
{
scanf("%lld", &A[i]);
A[i] = A[i] * (1 << (__builtin_popcount(i))) % mod;
}
for (int i = 0; i < up; i++)
scanf("%lld", &B[i]);
for (int i = 0; i < up; i++)
for (int k = 0; k <= m; k++)
{
a[k][i] = (__builtin_popcount(i) == k)? A[i] : 0;
b[k][i] = (__builtin_popcount(i) == k)? B[i] : 0;
}
for (int k = 0; k <= m; k++)
{
FWT_xor(a[k], up, 1);
FWT_xor(b[k], up, 1);
}
for (int h = 0; h <= m; h++)
for (int k = 0; k <= h; k++)
{
for (int i = 0; i < up; i++)
c[k][i] = (c[k][i] + a[h - k][i] * b[h][i] % mod) % mod;
}
for (int i = 0; i <= m; i++)
FWT_xor(c[i], up, -1);
ll ans = 0;
ll base = 1;
for (int i = 0; i < up; i++)
{
ans = ans + base * c[__builtin_popcount(i)][i] % mod;
ans %= mod;
base = base * 1526 % mod;
}
printf("%lld\n", ans);
return 0;
}
0%