#P10249. 【模板】多项式复合函数(加强版)

    ID: 11665 远端评测题 10007ms 2048MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>多项式O2优化快速傅里叶变换 FFT快速数论变换 NTT

【模板】多项式复合函数(加强版)

Background

Compared with P5373, this problem has larger constraints.

Problem Description

Given an nn-degree polynomial F(x)F(x) and an mm-degree polynomial G(x)G(x), you need to find an nn-degree polynomial H(x)H(x) that satisfies:

H(x)F(G(x)) (mod xn+1)H(x) \equiv F(G(x))\space (\text{mod }x^{n+1})

In other words, the polynomial you need should satisfy:

$$H(x) \equiv \sum_{i=0}^n [x^i]F(x)\times G(x)^i \space (\text{mod }x^{n+1})$$

Take all coefficients of the result modulo 998244353998244353.

Input Format

The first line contains two positive integers n,mn,m, which are the degrees of F(x)F(x) and G(x)G(x), respectively.

The second line contains n+1n+1 non-negative integers fif_i, where fif_i is the coefficient of the ii-th power term of F(x)F(x).

The third line contains m+1m+1 non-negative integers gig_i, where gig_i is the coefficient of the ii-th power term of G(x)G(x).

Output Format

Output one line with n+1n+1 non-negative integers, representing the coefficients of H(x)H(x) from low degree to high degree.

4 3
1 2 3 4 5
1 2 3 4
15 80 300 892 2069

Hint

Constraints:

  • 1mn2000001\le m \le n \le 200000
  • fi,gi[0,998244353)Zf_i,g_i \in [0,998244353)\cap \mathbb Z
Test Point ID m,nm,n\le
1,21,2 3000030000
3,43,4 5000050000
5,65,6 100000100000
7,87,8 150000150000
9,109,10 200000200000

Translated by ChatGPT 5