AT_arc230_c.Buildings

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer NN that is at least 22, and N−1N-1 integers C1,C2,…,CN−1C_1,C_2,\dots ,C_{N-1}.

There are NN buildings lined up on a number line. The ii-th building stands at position ii and has height HiH_i. It is known that (H1,H2,…,HN)(H_1,H_2,\dots ,H_N) is a permutation of (1,2,…,N)(1,2,\dots ,N), but the specific values of H1,H2,…,HNH_1,H_2,\dots ,H_N are not known.

Find the number, modulo 998244353998244353, of possible sequences (H1,H2,…,HN)(H_1,H_2,\dots, H_N) such that the following condition holds for all of x=1,2,…,N−1x=1,2,\dots, N-1.

  • The number of buildings visible from position x+0.5x+0.5 is CxC_x. Here, the ii-th building is visible if and only if there is no building with height greater than HiH_i between position x+0.5x+0.5 and position ii.

给定一个不小于 22 的整数 NN,以及 N−1N-1 个整数 C1,C2,…,CN−1C_1,C_2,\dots ,C_{N-1}。

在一条数轴上并排矗立着 NN 栋建筑。第 ii 栋建筑位于位置 ii,其高度为 HiH_i。已知 (H1,H2,…,HN)(H_1,H_2,\dots ,H_N) 是 (1,2,…,N)(1,2,\dots ,N) 的一个排列,但 H1,H2,…,HNH_1,H_2,\dots ,H_N 的具体取值未知。

求满足以下条件的序列 (H1,H2,…,HN)(H_1,H_2,\dots, H_N) 的个数(对 998244353998244353 取模):

  • 对每个 x=1,2,…,N−1x = 1,2,\dots, N-1,从位置 x+0.5x+0.5 处可见的建筑数量恰好为 CxC_x。
    其中,第 ii 栋建筑可见,当且仅当在位置 x+0.5x+0.5 与位置 ii 之间不存在高度严格大于 HiH_i 的建筑。

输入格式

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

NN
C1C_1 C2C_2 …\dots CN−1C_{N-1}

输入从标准输入中按以下格式给出:

NN
C1C_1 C2C_2 …\dots CN−1C_{N-1}

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    4
    2 2 3

    输出#1

    3
  • 输入#2

    3
    2 1

    输出#2

    0
  • 输入#3

    7
    3 3 3 3 4 4

    输出#3

    85

说明/提示

Sample 1 Explanation:
For example, (H1,H2,H3,H4)=(3,4,2,1)(H_1,H_2,H_3,H_4)=(3,4,2,1) satisfies the condition. Indeed,

  • For x=1x=1, the buildings visible from position x+0.5=1.5x+0.5=1.5 are the first and second buildings; there are 2=C12=C_1 such buildings.

  • For x=2x=2, the buildings visible from position x+0.5=2.5x+0.5=2.5 are the second and third buildings; there are 2=C22=C_2 such buildings.

  • For x=3x=3, the buildings visible from position x+0.5=3.5x+0.5=3.5 are the second, third, and fourth buildings; there are 3=C33=C_3 such buildings.

There are three sequences (H1,H2,H3,H4)(H_1,H_2,H_3,H_4) satisfying the condition, including this one.

Sample 2 Explanation:
There may be no sequence (H1,H2,…,HN)(H_1,H_2,\dots, H_N) satisfying the condition.

Constraints

  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤Cx≤N1\le C_x\le N
  • All input values are integers.

样例 1 解释:
例如,(H1,H2,H3,H4)=(3,4,2,1)(H_1,H_2,H_3,H_4)=(3,4,2,1) 满足条件。事实上,

  • 当 x=1x=1 时,从位置 x+0.5=1.5x+0.5=1.5 处可见的建筑物为第一栋和第二栋;这样的建筑物共有 2=C12=C_1 栋。

  • 当 x=2x=2 时,从位置 x+0.5=2.5x+0.5=2.5 处可见的建筑物为第二栋和第三栋;这样的建筑物共有 2=C22=C_2 栋。

  • 当 x=3x=3 时,从位置 x+0.5=3.5x+0.5=3.5 处可见的建筑物为第二栋、第三栋和第四栋;这样的建筑物共有 3=C33=C_3 栋。

满足条件的序列 (H1,H2,H3,H4)(H_1,H_2,H_3,H_4) 共有三个,本例即为其中之一。

样例 2 解释:
可能不存在满足条件的序列 (H1,H2,…,HN)(H_1,H_2,\dots, H_N)。

约束条件

  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤Cx≤N1\le C_x\le N
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页