A14345 | Oolimry and Suffix Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array.
More formally, given a suffix array of length $n$ and having an alphabet size $k$ , count the number of strings that produce such a suffix array.
Let $s$ be a string of length $n$ . Then the $i$ -th suffix of $s$ is the substring $s[i \ldots n-1]$ . A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is $[3,2,4,1,0,5,6]$ as the array of sorted suffixes is $[\texttt{imry},\texttt{limry},\texttt{mry},\texttt{olimry},\texttt{oolimry},\texttt{ry},\texttt{y}]$ .
A string $x$ is lexicographically smaller than string $y$ , if either $x$ is a prefix of $y$ (and $x\neq y$ ), or there exists such $i$ that $x_i < y_i$ , and for any $1\leq j < i$ , $x_j = y_j$ .
More formally, given a suffix array of length $n$ and having an alphabet size $k$ , count the number of strings that produce such a suffix array.
Let $s$ be a string of length $n$ . Then the $i$ -th suffix of $s$ is the substring $s[i \ldots n-1]$ . A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is $[3,2,4,1,0,5,6]$ as the array of sorted suffixes is $[\texttt{imry},\texttt{limry},\texttt{mry},\texttt{olimry},\texttt{oolimry},\texttt{ry},\texttt{y}]$ .
A string $x$ is lexicographically smaller than string $y$ , if either $x$ is a prefix of $y$ (and $x\neq y$ ), or there exists such $i$ that $x_i < y_i$ , and for any $1\leq j < i$ , $x_j = y_j$ .
输入格式
The first line contain 2 integers $n$ and $k$ ( $1 \leq n \leq 200000,1 \leq k \leq 200000$ ) — the length of the suffix array and the alphabet size respectively.
The second line contains $n$ integers $s_0, s_1, s_2, \ldots, s_{n-1}$ ( $0 \leq s_i \leq n-1$ ) where $s_i$ is the $i$ -th element of the suffix array i.e. the starting position of the $i$ -th lexicographically smallest suffix. It is guaranteed that for all $0 \leq i< j \leq n-1$ , $s_i \neq s_j$ .
The second line contains $n$ integers $s_0, s_1, s_2, \ldots, s_{n-1}$ ( $0 \leq s_i \leq n-1$ ) where $s_i$ is the $i$ -th element of the suffix array i.e. the starting position of the $i$ -th lexicographically smallest suffix. It is guaranteed that for all $0 \leq i< j \leq n-1$ , $s_i \neq s_j$ .
输出格式
Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo $998244353$ .
输入输出样例
输入 #1
3 2 0 2 1
输出 #1
1
输入 #2
5 1 0 1 2 3 4
输出 #2
0
输入 #3
6 200000 0 1 2 3 4 5
输出 #3
822243495
输入 #4
7 6 3 2 4 1 0 5 6
输出 #4
36
In the first test case, "abb" is the only possible solution.
In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal.
In the fourth test case, one possible string is "ddbacef".
Please remember to print your answers modulo $998244353$ .
In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal.
In the fourth test case, one possible string is "ddbacef".
Please remember to print your answers modulo $998244353$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted