CF1648C.Tyler and Strings
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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=y .
Because the answer can be too large, print it modulo 998244353 .
输入格式
The first line contains two integers n and m ( 1≤n,m≤200000 ) — the lengths of strings s and t respectively.
The second line contains n integers s1,s2,s3,…,sn ( 1≤si≤200000 ) — letters of the string s .
The third line contains m integers t1,t2,t3,…,tm ( 1≤ti≤200000 ) — 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 998244353 .
输入输出样例
输入#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 [122] and [212] . The string [221] is lexicographically larger than the string [2121] , so we don't count it.
In the second example, all strings count except [4321] , so the answer is 4!−1=23 .
In the third example, only the string [1112] counts.