E - Existence Counting Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 700700

問題文

整数 N,KN,K が与えられます。このとき、以下の条件を全て満たす長さ KK の数列 a=(a1,a2,,aK)a=(a_1,a_2,\dots,a_K) を考えます。

  • aia_i1aiN1 \le a_i \le N を満たす整数である
  • aa の全ての要素は相異なる

aa として考えられる数列を辞書順に全て並べた 「数列の列」 を辞書 ss とします。

辞書 ss 中に存在する数列 PP が与えられるので、整数 t=1,2,,Nt=1,2,\dots,N に対して以下の質問に答えてください。

  • 以下の条件を全て満たす数列 bb の個数を 998244353998244353 で割った余りを求めよ。
    • 数列 bb は辞書 ss 中に存在する。
    • 数列 bb 中に整数 tt が含まれる。
    • 数列 bb は辞書順で数列 PP 以下である。
数列の辞書順とは? 数列 A=(A1,,AA)A = (A_1, \ldots, A_{|A|})B=(B1,,BB)B = (B_1, \ldots, B_{|B|}) より辞書順で真に小さいとは、下記の 1. と 2. のどちらかが成り立つことを言います。
  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|\} が存在して、下記の 22 つがともに成り立つ。
    • (A1,,Ai1)=(B1,,Bi1)(A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1})
    • Ai<BiA_i < B_i

制約

  • 入力は全て整数
  • 1KN3×1051 \le K \le N \le 3 \times 10^5
  • PP は問題文中の条件を満たす。

入力

入力は以下の形式で標準入力から与えられる。

NN KK
P1P_1 P2P_2 \dots PKP_K

出力

全体で NN 行出力せよ。
このうち ii 行目には、 t=it=i であるときの質問の答えを整数として出力せよ。


入力例 1Copy

Copy
4 2
3 2

出力例 1Copy

Copy
5
5
4
2

この入力では、 N=4,K=2N=4,K=2 です。
このとき、辞書 s=((1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(4,3))s=((1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(4,3)) となります。

辞書 ss に含まれ、かつ辞書順で (3,2)(3,2) 以下である数列のうち、

  • 11 が含まれるものは (1,2),(1,3),(1,4),(2,1),(3,1)(1,2),(1,3),(1,4),(2,1),(3,1)55
  • 22 が含まれるものは (1,2),(2,1),(2,3),(2,4),(3,2)(1,2),(2,1),(2,3),(2,4),(3,2)55
  • 33 が含まれるものは (1,3),(2,3),(3,1),(3,2)(1,3),(2,3),(3,1),(3,2)44
  • 44 が含まれるものは (1,4),(2,4)(1,4),(2,4)22

です。


入力例 2Copy

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

出力例 2Copy

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

Score: 700700 points

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 1Copy

Copy
4 2
3 2

Sample Output 1Copy

Copy
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))((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 2Copy

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

Sample Output 2Copy

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


2025-03-30 (Sun)
08:20:12 +00:00