luogu#P4717. 【模板】快速莫比乌斯 / 沃尔什变换 (FMT / FWT)

    ID: 3693 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>快速沃尔什变换 FWT快速莫比乌斯变换 FMT

【模板】快速莫比乌斯 / 沃尔什变换 (FMT / FWT)

Problem Description

Given two sequences AA and BB of length 2n2^n, define

Ci=jk=iAj×BkC_i=\sum_{j\oplus k = i}A_j \times B_k

Compute CC respectively when \oplus is OR, AND, and XOR.

Input Format

The first line contains an integer nn.
The second line contains 2n2^n numbers A0,A1,,A2n1A_0, A_1, \ldots, A_{2^n-1}.
The third line contains 2n2^n numbers B0,B1,,A2n1B_0, B_1, \ldots, A_{2^n-1}.

Output Format

Output three lines. Each line contains 2n2^n numbers, representing the values of C0,C1,,C2n1C_0, C_1, \ldots, C_{2^n-1} when \oplus is OR, AND, and XOR, respectively, taken mod 998244353\bmod\ 998244353.

2
2 4 6 8
1 3 5 7

2 22 46 250
88 64 112 56
100 92 68 60

Hint

1n171 \le n \le 17.

Translated by ChatGPT 5