QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 512 MB Total points: 100

#1610. 数列

統計

九条可怜手上有一个长度为 $n$ 的整数数列 $r_i$ ,她现在想要构造一个长度为 $n$ 的,满足如下条件的整数数列 $A$:

  • $1\leq A_i \leq r_i$。
  • 对于任意 $3 \leq i \leq n$,令 $R$ 为 $A_1$ 至 $A_{i-2}$ 中大于等于 $A_{i-1}$ 的最小值,$L$ 为 $A_1$ 至 $A_{i-2}$ 中小于等于 $A_{i-1}$ 的最大值。$A_i$ 必须满足 $L \leq A_i \leq R$。如果不存在大于等于 $A_{i-1}$ 的,那 么 $R = +\infty$;如果不存在小于等于 $A_{i-1}$ 的,那么 $L = −\infty$。

现在可怜想要知道共有多少不同的数列满足这个条件。两个数列 $A$ 和 $B$ 是不同的当且仅当至少存在一个位置 $i$ 满足 $A_i \neq B_i$。

输入格式

第一行输入一个整数 $n$,第二行输入 $n$ 个整数 $r_i$。

输出格式

输出一个整数表示方案数,答案可能很大,对 $998244353$ 取模后输出。

样例数据

样例输入

3
2 2 2

样例输出

6

样例解释

满足条件的序列有 $[1, 1, 1], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 2]$ 。

子任务

测试点编号 $n$ $r_i$
$1$ $\leq 7$ $\leq 7$
$2$
$3$ $\leq 50$ $\leq 10$
$4$
$5$ $\leq 16$
$6$
$7$ $\leq 50$
$8$
$9$ $\leq 150$
$10$

对于全部数据,保证 $n\ge 1,r_i\ge 1$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.