#P16313. [ICPC 2023 Jinan R] 向未来说你好

[ICPC 2023 Jinan R] 向未来说你好

Problem Description

:::epigraph “Uh... um, can we restart our friendship?”

“What do you mean... you mean, start over?”

“...” :::

A long, long time ago, Xiaoqingyu and his best friend F\mathcal{F} prepared a programming contest together. They prepared a total of nn problems, numbered with integers from 11 to nn. The ii-th problem (1in1 \leq i \leq n) has a difficulty rating aia_i.

Time flies. Fifteen months have passed since the contest they held. Xiaoqingyu is no longer an Informatics Olympiad contestant, but has transitioned into a coach. However, they once agreed to hold a series of tournaments together.

And Xiaoqingyu has not forgotten it.

Now, Xiaoqingyu wants to group these nn problems into several training sessions. To make sure the story background in the statements is consistent, Xiaoqingyu wants to partition these nn problems into several intervals. A partition scheme can be written as an integer sequence 0=r0<r1<r2<<rk=n0 = r_0 < r_1 < r_2 < \cdots < r_k = n, meaning there are kk training sessions, where the ii-th session contains all problems with indices from (ri1+1)(r_{i - 1} + 1) to rir_i (both ends inclusive).

Besides, Xiaoqingyu does not want any session to be too unbalanced. If a session contains a hard problem, then this session should contain more problems. Formally, if problem jj is in the ii-th session (that is, ri1<jrir_{i - 1} < j \leq r_i), then the inequality riri1ajr_i - r_{i - 1} \geq a_j must hold.

Xiaoqingyu is curious about how many partition schemes can satisfy all the requirements above, and denotes the number by f(a)f(a). This problem is very easy for him, so he computed the answer effortlessly.

On the day before these sessions, Xiaoqingyu suddenly realized that these problems were too hard for the contestants. Therefore, he came up with a new easy problem whose difficulty rating is only 11. He is curious: for each 1jn1 \leq j \leq n, if we define the sequence a(j)a^{(j)} as follows, then what is the value of f(a(j))f(a^{(j)})?

$$a^{(j)}_i = \begin{cases}1 & i = j \\ a_i & \text{otherwise}\end{cases}$$

Since the value of f(a(j))f(a^{(j)}) can be very large, you only need to output it modulo 998244353998\,244\,353.

Input Format

Each test file contains only one set of testdata.

The first line contains an integer nn (1n2×1051 \leq n \leq 2 \times 10^5), indicating the number of problems.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (1ain1 \leq a_i \leq n), where aia_i denotes the difficulty rating of the ii-th problem.

Output Format

Output one line containing nn integers separated by single spaces, where the ii-th integer is the value of f(a(i))f(a^{(i)}) modulo 998244353998\,244\,353.

Please do not output extra spaces at the end of the line, otherwise your answer may be judged as wrong!

5
1 3 2 1 2
3 6 3 3 6

Hint

In the sample, for j=1j = 1, we have a(j)=[1,3,2,1,2]a^{(j)} = [1, 3, 2, 1, 2]. There are 33 ways to assign the problems into sessions, as follows:

  • [1][1], [3,2,1,2][3, 2, 1, 2]
  • [1,3,2][1, 3, 2], [1,2][1, 2]
  • [1,3,2,1,2][1, 3, 2, 1, 2]

For j=2j = 2, we have a(j)=[1,1,2,1,2]a^{(j)} = [1, 1, 2, 1, 2]. There are 66 ways to assign the problems into sessions, as follows:

  • [1][1], [1][1], [2,1,2][2, 1, 2]
  • [1][1], [1,2][1, 2], [1,2][1, 2]
  • [1][1], [1,2,1,2][1, 2, 1, 2]
  • [1,1][1, 1], [2,1,2][2, 1, 2]
  • [1,1,2][1, 1, 2], [1,2][1, 2]
  • [1,1,2,1,2][1, 1, 2, 1, 2]

For j=3j = 3 and j=4j = 4, all schemes are the same as those when j=1j = 1.

For j=5j = 5, we have a(j)=[1,3,2,1,1]a^{(j)} = [1, 3, 2, 1, 1]. There are 66 ways to assign the problems into sessions, as follows:

  • [1][1], [3,2,1][3, 2, 1], [1][1]
  • [1][1], [3,2,1,1][3, 2, 1, 1]
  • [1,3,2][1, 3, 2], [1][1], [1][1]
  • [1,3,2][1, 3, 2], [1,1][1, 1]
  • [1,3,2,1][1, 3, 2, 1], [1][1]
  • [1,3,2,1,1][1, 3, 2, 1, 1]

Translated by ChatGPT 5