题目大意:给你两个多项式$A,B$,求多项式$C$使得:
$$
C_n=\sum\limits_{x\oplus y=n}A_xB_y
$$
题解:$FWT$
卡点:无
C++ Code:
#include <cstdio>
#include <cctype>
namespace __IO {
int ch;
inline int read() {
while (isspace(ch = getchar())) ;
return ch & 15;
}
}
using __IO::read; #define maxn 2097152 int lim;
inline void init(const int n) {
lim = 1; while (lim < n) lim <<= 1;
}
inline void FWT(long long *A, const int op = 1) {
for (register int mid = 1; mid < lim; mid <<= 1)
for (register int i = 0; i < lim; i += mid << 1)
for (register int j = 0; j < mid; ++j) {
const long long X = A[i + j], Y = A[i + j + mid];
A[i + j] = X + Y, A[i + j + mid] = X - Y;
}
if (!op) for (long long *i = A; i != A + lim; ++i) *i /= lim;
} int n;
long long A[maxn], B[maxn];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) A[i] = read();
for (int i = 0; i < n; ++i) B[i] = read();
init(n + n);
FWT(A), FWT(B);
for (int i = 0; i < lim; ++i) A[i] = A[i] * B[i];
FWT(A, 0);
for (int i = 0; i < n; ++i) printf("%lld ", A[i]); puts("");
return 0;
}