#P7512. 「Byakkai OI 2021」Eaquira

「Byakkai OI 2021」Eaquira

Description

Given nn, take the integer points on the number line in [1,n][1,n].

Define a maximal consecutive black segment as an interval [L,R][L,R] with 1LRp1 \le L \le R \le p, such that all intervals with indices in [L,R][L,R] are black, and it cannot be extended further; that is, the intervals with indices L1L-1 (if it exists; same below) and R+1R+1 are both white.

First, you need to partition them into several intervals [l1,r1],[l2,r2],,[lp,rp][l_1,r_1],[l_2,r_2],\dots,[l_p,r_p], satisfying l1=1l_1 = 1, rp=nr_p = n, and for 1i<p1 \le i < p we have ri=li+11r_i = l_{i+1}-1; for 1ip1 \le i \le p we have liril_i \le r_i.

Second, you need to mark each interval as black or white, but it is not allowed that both the first interval and the pp-th interval are marked black at the same time.

Third, within each interval, select a subinterval, called a wonderful subinterval.

Fourth, in each maximal consecutive black segment, select one black interval, called a wonderful black interval.

Fifth, among all maximal consecutive black segments, designate some of them as wonderful maximal consecutive black segments.

Define the weight of a plan determined by the above steps as the sum of the number of black intervals and the number of wonderful maximal consecutive black segments.

Originally, I hoped you would compute, for s=0,1,2,,ns = 0,1,2,\dots,n, the number of plans that make the final weight equal to ss. However, I have also prepared some easier challenges. See the input format for details.

The answer should be taken modulo 998244353998244353.

Input Format

One line with two integers n,typen,{\rm type}.

If type=0{\rm type} = 0, you need to compute, for 0sn0 \le s \le n, the number of plans with weight ss.
If type=1{\rm type} = 1, you need to compute the total number of plans over all 0sn0 \le s \le n.

Output Format

If type=0{\rm type} = 0, output one line with n+1n+1 non-negative integers, in order, representing the answers for s=0,1,2,,ns = 0,1,2,\dots,n.
If type=1{\rm type} = 1, output one line with one non-negative integer, representing the answer.

3 0
6 13 17 4
5 1
1035

Hint

Sample Explanation

Below, 00 denotes black and 11 denotes white.

For the first sample, consider the 44 partitions of [1,3][1,3]:

  • [1,1],[2,2],[3,3][1,1],[2,2],[3,3]:
    At this time, the number of ways to choose an unordered pair is 11.
    Considering the black/white marking of each interval, there are the following 44 plans:
    • 001,100001,100: in this case, you may choose whether to mark the only maximal consecutive black segment as wonderful or not, so the weight is 22 or 33. The number of ways to choose the wonderful black interval is 22.
    • 101101: in this case, you may choose whether to mark the only maximal consecutive black segment as wonderful or not, so the weight is 11 or 22. The number of ways to choose the wonderful black interval is 11.
  • [1,2],[3,3][1,2],[3,3] or [1,1],[2,3][1,1],[2,3]:
    At this time, the number of ways to choose an unordered pair is 33.
    Considering the black/white marking of each interval, there are the following 22 plans:
    • 01,1001,10: in this case, you may choose whether to mark the only maximal consecutive black segment as wonderful or not, so the weight is 11 or 22. The number of ways to choose the wonderful black interval is 11.
  • [1,3][1,3]:
    At this time, the number of ways to choose an unordered pair is 66.
    Considering the black/white marking of each interval, there is the following 11 plan:
    • 11: in this case, the weight is 00, the total number of plans is 66, and the number of ways to choose the wonderful black interval is 11. Therefore, the number of plans with weight 00 is 6×1=66 \times 1 = 6, the number of plans with weight 11 is 1×1+2×3×2×1=131 \times 1 + 2 \times 3 \times 2 \times 1 = 13, the number of plans with weight 22 is $1 \times 2 \times 2 + 1 \times 1 + 2 \times 3 \times 2 \times 1 = 17$, and the number of plans with weight 33 is 1×2×2=41 \times 2 \times 2 = 4.

For the second sample, no explanation is provided.

Constraints

This problem uses bundled testdata.

The specific subtask constraints and scores are as follows:

Subtask ID Score nn \le type={\rm type} = Time limit / s
00 11 88 00 11
11 44 1313 11
22 88 300300
33 55 7070 00
44 1010 5×1035 \times 10^3 11
55 88 300300 00
66 1212 2×1052 \times 10^5 11
77 2222 10310^3 00 22
88 3030 2×1052 \times 10^5 2.52.5

For all testdata, 1n2×1051 \le n \le 2 \times 10^5, type{0,1}{\rm type} \in \{0,1\}.

Translated by ChatGPT 5