QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#6199. Counting Circles

Statistics

Given integers $n, y$ and an integer sequence $A = \{a_1, a_2, \dots, a_n\}$ of length $n$, it is guaranteed that the sequence $A$ is monotonically non-decreasing or monotonically non-increasing.

Construct a directed graph $G(V, E)$, where $V = \{1, 2, \dots, n\}$ and $E = \{(i, j) \mid 1 \leq i, j \leq n, a_i \geq j\}$. Note that the graph $G$ may contain self-loops.

A subset of edges $T \subseteq E$ is defined as valid if and only if the in-degree and out-degree of every vertex in the graph $G'(V, T)$ are at most $1$. A self-loop contributes $1$ to both the in-degree and out-degree of its corresponding vertex. The weight of a valid edge subset $T$ is defined as $y^{\mathrm{cycle}(T)}$, where $\mathrm{cycle}(T)$ denotes the number of cycles in the graph $G'(V, T)$, and a self-loop is considered a cycle.

Specifically, we define $0^0 = 1$.

For all integers $0 \leq k \leq n$, calculate the sum of weights of all valid edge subsets of size $k$, modulo $998244353$.

Input

The first line contains two integers $n, y$. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ describing the sequence $A$.

Output

Output $n+1$ integers on a single line, where the $i$-th integer represents the sum of weights of all valid edge subsets of size $i-1$, modulo $998244353$.

Examples

Input 1

2 2
2 2

Output 1

1 6 6

Note 1

In graph $G$, there are two vertices and edges $\{(1, 1), (1, 2), (2, 1), (2, 2)\}$.

The only valid edge subset of size $0$ is the empty set, which has a weight of $1$. Thus, the sum of weights for size $0$ is $1$.

The valid edge subsets of size $1$ are $\{(1, 1)\}, \{(2, 2)\}, \{(1, 2)\}, \{(2, 1)\}$, with weights $2, 2, 1, 1$ respectively, for a total sum of $6$.

The valid edge subsets of size $2$ are $\{(1, 1), (2, 2)\}, \{(1, 2), (2, 1)\}$, with weights $4, 2$ respectively, for a total sum of $6$.

Constraints

For $100\%$ of the data, $1 \leq n \leq 10^5$, $0 \leq y < 998244353$, $0 \leq a_i \leq n$. It is guaranteed that the sequence $A$ is monotonically non-decreasing or monotonically non-increasing.

The first $5$ subtasks satisfy the condition that $A$ is monotonically non-decreasing. The special properties and scores are shown in the table below.

Subtask $n \leq$ Special Property Score
$1$ $8$ None $1$
$2$ $15$ $y=0$ $9$
$3$ $2000$ None $10$
$4$ $75000$ $y=1$ $15$
$5$ $10^5$ None $15$

The last $4$ subtasks satisfy the condition that $A$ is monotonically non-increasing. Let $b_i = \sum_{j=1}^n [a_j \geq i]$. The special properties and scores are shown in the table below.

Subtask $n \leq$ Special Property Score
$6$ $15$ $y=0$ $5$
$7$ $2000$ None $10$
$8$ $75000$ For all $i$ such that $a_i \geq i$, $a_i \geq b_i$ $15$
$9$ $10^5$ None $20$

Please be aware of the impact of algorithm constants on execution time.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.