F - Convolution Editorial /

Time Limit: 5 sec / Memory Limit: 1024 MB

配点 : 100100

問題文

整数列 a0,a1,...,aN1a_0, a_1, ..., a_{N - 1}b0,b1,...,bM1b_0, b_1, ..., b_{M - 1} が与えられます。整数列 c0,c1,...,c(N1)+(M1)c_0, c_1, ..., c_{(N - 1) + (M - 1)} を求めてください。

ただし、ci=j=0iajbijmod998244353c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353

です

制約

  • 1N,M5242881 \leq N, M \leq 524288
  • 0ai,bi<9982443530 \leq a_i, b_i < 998244353

入力Copy

Copy
NN MM
a0a_0 a1a_1 ... aN1a_{N-1}
b0b_0 b1b_1 ... bM1b_{M-1}

出力Copy

Copy
c0c_0 c1c_1 ... c(N1)+(M1)c_{(N - 1) + (M - 1)}

入力例 1Copy

Copy
4 5
1 2 3 4
5 6 7 8 9

出力例 1Copy

Copy
5 16 34 60 70 70 59 36

入力例 2Copy

Copy
1 1
10000000
10000000

出力例 2Copy

Copy
871938225

Score : 100100 points

Problem Statement

You are given two integer arrays a0,a1,...,aN1a_0, a_1, ..., a_{N - 1} and b0,b1,...,bM1b_0, b_1, ..., b_{M - 1}. Calculate the array c0,c1,...,c(N1)+(M1)c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by ci=j=0iajbijmod998244353c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.

Constraints

  • 1N,M5242881 \leq N, M \leq 524288
  • 0ai,bi<9982443530 \leq a_i, b_i < 998244353
  • All values in Input are integer.

Input

Input is given from Standard Input in the following format:

NN MM
a0a_0 a1a_1 ... aN1a_{N-1}
b0b_0 b1b_1 ... bM1b_{M-1}

Output

Print the answer in the following format:

c0c_0 c1c_1 ... c(N1)+(M1)c_{(N - 1) + (M - 1)}

Sample Input 1Copy

Copy
4 5
1 2 3 4
5 6 7 8 9

Sample Output 1Copy

Copy
5 16 34 60 70 70 59 36

Sample Input 2Copy

Copy
1 1
10000000
10000000

Sample Output 2Copy

Copy
871938225

Source Name

Based on Library Checker (Convolution) (APACHE LICENSE, V2.0)


2025-04-24 (Thu)
01:16:39 +00:00