A14924 | Tyler and Strings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
While looking at the kitchen fridge, the little boy Tyler noticed magnets with symbols, that can be aligned into a string $s$ .
Tyler likes strings, and especially those that are lexicographically smaller than another string, $t$ . After playing with magnets on the fridge, he is wondering, how many distinct strings can be composed out of letters of string $s$ by rearranging them, so that the resulting string is lexicographically smaller than the string $t$ ? Tyler is too young, so he can't answer this question. The alphabet Tyler uses is very large, so for your convenience he has already replaced the same letters in $s$ and $t$ to the same integers, keeping that different letters have been replaced to different integers.
We call a string $x$ lexicographically smaller than a string $y$ if one of the followings conditions is fulfilled:
- There exists such position of symbol $m$ that is presented in both strings, so that before $m$ -th symbol the strings are equal, and the $m$ -th symbol of string $x$ is smaller than $m$ -th symbol of string $y$ .
- String $x$ is the prefix of string $y$ and $x \neq y$ .
Because the answer can be too large, print it modulo $998\,244\,353$ .
Tyler likes strings, and especially those that are lexicographically smaller than another string, $t$ . After playing with magnets on the fridge, he is wondering, how many distinct strings can be composed out of letters of string $s$ by rearranging them, so that the resulting string is lexicographically smaller than the string $t$ ? Tyler is too young, so he can't answer this question. The alphabet Tyler uses is very large, so for your convenience he has already replaced the same letters in $s$ and $t$ to the same integers, keeping that different letters have been replaced to different integers.
We call a string $x$ lexicographically smaller than a string $y$ if one of the followings conditions is fulfilled:
- There exists such position of symbol $m$ that is presented in both strings, so that before $m$ -th symbol the strings are equal, and the $m$ -th symbol of string $x$ is smaller than $m$ -th symbol of string $y$ .
- String $x$ is the prefix of string $y$ and $x \neq y$ .
Because the answer can be too large, print it modulo $998\,244\,353$ .
输入格式
The first line contains two integers $n$ and $m$ ( $1 \le n, m \le 200\,000$ ) — the lengths of strings $s$ and $t$ respectively.
The second line contains $n$ integers $s_1, s_2, s_3, \ldots, s_n$ ( $1 \le s_i \le 200\,000$ ) — letters of the string $s$ .
The third line contains $m$ integers $t_1, t_2, t_3, \ldots, t_m$ ( $1 \le t_i \le 200\,000$ ) — letters of the string $t$ .
The second line contains $n$ integers $s_1, s_2, s_3, \ldots, s_n$ ( $1 \le s_i \le 200\,000$ ) — letters of the string $s$ .
The third line contains $m$ integers $t_1, t_2, t_3, \ldots, t_m$ ( $1 \le t_i \le 200\,000$ ) — letters of the string $t$ .
输出格式
Print a single number — the number of strings lexicographically smaller than $t$ that can be obtained by rearranging the letters in $s$ , modulo $998\,244\,353$ .
输入输出样例
输入 #1
3 4 1 2 2 2 1 2 1
输出 #1
2
输入 #2
4 4 1 2 3 4 4 3 2 1
输出 #2
23
输入 #3
4 3 1 1 1 2 1 1 2
输出 #3
1
In the first example, the strings we are interested in are $[1\, 2\, 2]$ and $[2\, 1\, 2]$ . The string $[2\, 2\, 1]$ is lexicographically larger than the string $[2\, 1\, 2\, 1]$ , so we don't count it.
In the second example, all strings count except $[4\, 3\, 2\, 1]$ , so the answer is $4! - 1 = 23$ .
In the third example, only the string $[1\, 1\, 1\, 2]$ counts.
In the second example, all strings count except $[4\, 3\, 2\, 1]$ , so the answer is $4! - 1 = 23$ .
In the third example, only the string $[1\, 1\, 1\, 2]$ counts.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted