AtCoder Regular Contest 212 (Div. 2)
翻译中…
Problem Statement
翻译中…
There is a permutation $P$ of $(1,2,\ldots,N)$ and an empty array $A$. Perform the following operation $N-1$ times on $P$:
翻译中…
- Choose two adjacent elements. Remove the smaller of the chosen elements from
$P$and concatenate the parts before and after the removed element. Append the removed element to the end of$A$.
翻译中…
Find the number, modulo $998244353$, of possible final sequences $A$ of length $N-1$.
翻译中…
Constraints
翻译中…
$2 \le N \le 2\times 10^5$$1 \le P_i \le N$$P$is a permutation of$(1,2,\ldots,N)$.- All input values are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
P_1 P_2 \ldots P_N
翻译中…
Output
翻译中…
Output the answer.
翻译中…
样例
Input #1
4
1 2 3 4
Output #1
6
All six permutations of $(1,2,3)$ are possible as the final $A$.
For example, $A=(2,1,3)$ can be obtained as follows:
- Choose $2,3$. Remove $2$, and now $P=(1,3,4), A=(2)$.
- Choose $1,3$. Remove $1$, and now $P=(3,4), A=(2,1)$.
- Choose $3,4$. Remove $3$, and now $P=(4), A=(2,1,3)$.
Input #2
3
3 1 2
Output #2
1
Input #3
24
10 24 3 4 8 14 5 2 22 9 21 1 15 6 13 23 18 12 7 17 19 16 20 11
Output #3
303178128
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。