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

    ID: 5451 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>快速沃尔什变换 FWT快速莫比乌斯变换 FMT

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

Problem Description

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

Ci=∑j⊕k=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,…,A2n−1A_0, A_1, \ldots, A_{2^n-1}.
The third line contains 2n2^n numbers B0,B1,…,A2n−1B_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,…,C2n−1C_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

Data Constraints

  • 1≤n≤171 \le n \le 17
  • 0≤ai,bi<9982443530\le a_i,b_i<998244353

Translated by ChatGPT 5