#arc174e. E - Existence Counting

E - Existence Counting

Score: 700700 points

问题陈述

给定整数 NNKK。考虑一个长度为 KK 的序列 a=(a1,a2,,aK)a=(a_1,a_2,\dots,a_K),它满足以下所有条件:

  • aia_i 是一个整数,使得 1aiN1 \le a_i \le N
  • aa 中的所有元素都是不同的。

让我们将所有可能的序列 aa 按字典序排列,形成一个称为字典 ss 的“序列序列”。

给定一个存在于字典 ss 中的序列 PP,对于每个整数 t=1,2,,Nt=1,2,\dots,N,回答以下问题:

  • 找出满足以下所有条件的序列 bb 的数量,对 998244353998244353 取模:
    • 序列 bb 存在于字典 ss 中。
    • 整数 tt 包含在序列 bb 中。
    • 序列 bb 字典序小于或等于序列 PP

序列的字典序是什么?如果满足以下 1. 或 2. 中的任一条件,则序列 A=(A1,,AA)A = (A_1, \ldots, A_{|A|}) 严格字典序小于 B=(B1,,BB)B = (B_1, \ldots, B_{|B|})

  1. A<B|A|<|B|(A1,,AA)=(B1,,BA)(A_{1},\ldots,A_{|A|}) = (B_1,\ldots,B_{|A|})
  2. 存在一个整数 1imin{A,B}1\leq i\leq \min\{|A|,|B|\},满足以下两个条件:
    • (A1,,Ai1)=(B1,,Bi1)(A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1})
    • Ai<BiA_i < B_i

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given integers NN and KK. Consider a sequence a=(a1,a2,,aK)a=(a_1,a_2,\dots,a_K) of length KK that satisfies all of the following conditions:

  • aia_i is an integer such that 1aiN1 \le a_i \le N.
  • All elements in aa are different.

Let us arrange all possible sequences aa in lexicographical order to form a "sequence of sequences" called the dictionary ss.

Given a sequence PP that exists in the dictionary ss, answer the following question for each integer t=1,2,,Nt=1,2,\dots,N:

  • Find the number, modulo 998244353998244353, of sequences bb that satisfy all of the following conditions:
    • The sequence bb exists in the dictionary ss.
    • The integer tt is contained in the sequence bb.
    • The sequence bb is lexicographically less than or equal to the sequence PP.

What is lexicographical order for sequences? A sequence A=(A1,,AA)A = (A_1, \ldots, A_{|A|}) is lexicographically strictly less than B=(B1,,BB)B = (B_1, \ldots, B_{|B|}) if and only if 1. or 2. below is satisfied:

  1. A<B|A|<|B| and (A1,,AA)=(B1,,BA)(A_{1},\ldots,A_{|A|}) = (B_1,\ldots,B_{|A|}).
  2. There is an integer 1imin{A,B}1\leq i\leq \min\{|A|,|B|\} that satisfies both of the following:
    • (A1,,Ai1)=(B1,,Bi1)(A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1})
    • Ai<BiA_i < B_i

Constraints

  • All input values are integers.
  • 1KN3×1051 \le K \le N \le 3 \times 10^5
  • PP satisfies the condition in the problem statement.

Input

The input is given from Standard Input in the following format:

NN KK

P1P_1 P2P_2 \dots PKP_K

Output

Print NN lines in total.
The ii-th line should contain the answer to the problem for t=it=i as an integer.

Sample Input 1

4 2
3 2

Sample Output 1

5
5
4
2

In this input, N=4,K=2N=4,K=2.
Here, the dictionary ss is $((1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(4,3))$.

Among the sequences in the dictionary ss that are lexicographically less than or equal to (3,2)(3,2),

  • five sequences contain 11: (1,2),(1,3),(1,4),(2,1),(3,1)(1,2),(1,3),(1,4),(2,1),(3,1),
  • five sequences contain 22: (1,2),(2,1),(2,3),(2,4),(3,2)(1,2),(2,1),(2,3),(2,4),(3,2),
  • four sequences contain 33: (1,3),(2,3),(3,1),(3,2)(1,3),(2,3),(3,1),(3,2),
  • two sequences contain 44: (1,4),(2,4)(1,4),(2,4).

Sample Input 2

18 13
5 13 11 2 18 1 10 15 17 4 12 7 3

Sample Output 2

925879409
905921009
665544804
665544719
783035803
349952762
349952758
349952757
349952757
349921178
212092637
710350150
378895603
129113201
129111892
129098081
129096772
110181652