102707: [AtCoder]ABC270 Ex - add 1

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

You are given a tuple of $N$ non-negative integers $A=(A_1,A_2,\ldots,A_N)$ such that $A_1=0$ and $A_N>0$.

Takahashi has $N$ counters. Initially, the values of all counters are $0$.
He will repeat the following operation until, for every $1\leq i\leq N$, the value of the $i$-th counter is at least $A_i$.

Choose one of the $N$ counters uniformly at random and set its value to $0$. (Each choice is independent of others.)
Increase the values of the other counters by $1$.

Print the expected value of the number of times Takahashi repeats the operation, modulo $998244353$ (see Notes).

Notes

It can be proved that the sought expected value is always finite and rational. Additionally, under the Constraints of this problem, when that value is represented as $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, one can prove that there is a unique integer $R$ such that $R \times Q \equiv P\pmod{998244353}$ and $0 \leq R \lt 998244353$. Find this $R$.

Constraints

  • $2\leq N\leq 2\times 10^5$
  • $0=A_1\leq A_2\leq \cdots \leq A_N\leq 10^{18}$
  • $A_N>0$
  • All values in the input are integers.

Input

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

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Print the expected value of the number of times Takahashi repeats the operation, modulo $998244353$.


Sample Input 1

2
0 2

Sample Output 1

6

Let $C_i$ denote the value of the $i$-th counter.

Here is one possible progression of the process.

  • Set the value of the $1$-st counter to $0$, and then increase the value of the other counter by $1$. Now, $(C_1,C_2)=(0,1)$.
  • Set the value of the $2$-nd counter to $0$, and then increase the value of the other counter by $1$. Now, $(C_1,C_2)=(1,0)$.
  • Set the value of the $1$-st counter to $0$, and then increase the value of the other counter by $1$. Now, $(C_1,C_2)=(0,1)$.
  • Set the value of the $1$-st counter to $0$, and then increase the value of the other counter by $1$. Now, $(C_1,C_2)=(0,2)$.

In this case, the operation is performed four times.

The probabilities that the process ends after exactly $1,2,3,4,5,\ldots$ operation(s) are $0,\frac{1}{4}, \frac{1}{8}, \frac{1}{8}, \frac{3}{32},\ldots$, respectively, so the sought expected value is $2\times\frac{1}{4}+3\times\frac{1}{8}+4\times\frac{1}{8}+5\times\frac{3}{32}+\dots=6$. Thus, $6$ should be printed.


Sample Input 2

5
0 1 3 10 1000000000000000000

Sample Output 2

874839568

Input

题意翻译

给定一个由非负整数组成的 $N$ 元组 $A=(A_1,A_2,\cdots,A_n)$,其中 $A_1=0$ 且 $A_N>0$。 有 $N$ 个初始值为 $0$ 的计数器。 需要进行下述操作,直到对于每个 $i$,第 $i$ 个计数器均至少为 $A_i$: > 均匀随机地选定某一个计数器,并将该计数器归零。其他的计数器增加 $1$。 输出操作次数的期望对 $998244353$ 取模的结果。

Output

得分:$600$分

问题描述

你得到了一个长度为$N$的非负整数元组$A=(A_1,A_2,\ldots,A_N)$,满足$A_1=0$和$A_N>0$。

Takahashi有$N$个计数器。最初,所有计数器的值都是$0$。

他将重复以下操作,直到对于每个$1\leq i\leq N$,第$i$个计数器的值至少为$A_i$。

以等概率选择$N$个计数器中的一个,并将其值设置为$0$。 (每次选择都是相互独立的。)
将其他计数器的值增加$1$。

输出Takahashi重复操作的期望次数,对$998244353$取模(见注释)。

注释

可以证明所求的期望值总是有限的且为有理数。此外,在本问题的约束条件下,当该值表示为$\frac{P}{Q}$,其中两个互素的整数$P$和$Q$表示,可以证明存在一个唯一的整数$R$,使得$R \times Q \equiv P\pmod{998244353}$且$0 \leq R \lt 998244353$。找到这个$R$。

约束

  • $2\leq N\leq 2\times 10^5$
  • $0=A_1\leq A_2\leq \cdots \leq A_N\leq 10^{18}$
  • $A_N>0$
  • 输入中的所有值都是整数。

输入

输入通过标准输入给出,格式如下:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

输出

输出Takahashi重复操作的期望次数,对$998244353$取模。


样例输入1

2
0 2

样例输出1

6

令$C_i$表示第$i$个计数器的值。

以下是过程的一种可能的进程。

  • 将第$1$个计数器的值设置为$0$,然后将其他计数器的值增加$1$。现在,$(C_1,C_2)=(0,1)$。
  • 将第$2$个计数器的值设置为$0$,然后将其他计数器的值增加$1$。现在,$(C_1,C_2)=(1,0)$。
  • 将第$1$个计数器的值设置为$0$,然后将其他计数器的值增加$1$。现在,$(C_1,C_2)=(0,1)$。
  • 将第$1$个计数器的值设置为$0$,然后将其他计数器的值增加$1$。现在,$(C_1,C_2)=(0,2)$。

在这种情况下,操作执行了四次。

过程在恰好执行$1,2,3,4,5,\ldots$次操作后结束的概率分别为$0,\frac{1}{4}, \frac{1}{8}, \frac{1}{8}, \frac{3}{32},\ldots$,因此所求的期望值为$2\times\frac{1}{4}+3\times\frac{1}{8}+4\times\frac{1}{8}+5\times\frac{3}{32}+\dots=6$。 因此,应输出$6$。


样例输入2

5
0 1 3 10 1000000000000000000

样例输出2

874839568

加入题单

上一题 下一题 算法标签: