#abc263e. E - Sugoroku 3

E - Sugoroku 3

Score : 500500 points

问题陈述

NN 个正方形,分别称为第 1 个正方形到第 NN 个正方形。你从第 1 个正方形开始。

从第 1 个正方形到第 N1N-1 个正方形上的每个正方形都有一颗骰子。在第 ii 个正方形上的骰子标记着从 00AiA_i 的整数,且每个数字出现的概率相等。(各骰子的滚动是相互独立的。)

直到你到达第 NN 个正方形之前,你需要重复在当前所在的正方形上投掷骰子。这里的规则是:如果在第 xx 个正方形上投掷骰子得到整数 yy,则你将移动到第 x+yx+y 个正方形。

求模 998244353998244353 后,投掷骰子次数的期望值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN squares called Square 11 though Square NN. You start on Square 11.

Each of the squares from Square 11 through Square N1N-1 has a die on it. The die on Square ii is labeled with the integers from 00 through AiA_i, each occurring with equal probability. (Die rolls are independent of each other.)

Until you reach Square NN, you will repeat rolling a die on the square you are on. Here, if the die on Square xx rolls the integer yy, you go to Square x+yx+y.

Find the expected value, modulo 998244353998244353, of the number of times you roll a die.

Notes

It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented PQ\frac{P}{Q} using two coprime integers PP and QQ, there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Find this RR.

Constraints

  • 2N2×1052 \le N \le 2 \times 10^5
  • 1AiNi(1iN1)1 \le A_i \le N-i(1 \le i \le N-1)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots AN1A_{N-1}

Output

Print the answer.

Sample Input 1

3
1 1

Sample Output 1

4

The sought expected value is 44, so 44 should be printed.

Here is one possible scenario until reaching Square NN:

  • Roll 11 on Square 11, and go to Square 22.
  • Roll 00 on Square 22, and stay there.
  • Roll 11 on Square 22, and go to Square 33.

This scenario occurs with probability 18\frac{1}{8}.

Sample Input 2

5
3 1 2 1

Sample Output 2

332748122

update @ 2024/3/10 11:08:00