307960: CF1442B. Identify the Operations
Memory Limit:512 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Identify the Operations
题意翻译
给你两个数组$\{a_i\},\{b_i\}$,长度分别为$n,m$。 满足 - $\{a_i\}$是大小为$n$的置换(其实就是一个$1$~$n$的排列) - $\forall x \in \{b_i\} ,x\in \{a_i \}$。 - $\{b_i\}$中所有元素不重复 你需要进行$m$次操作,每次你要从$a$中选一个下标$t$,然后选择$a$中下标为$t+1$或者$t-1$的数放在$c$数组的末尾(如果$a$数组存在下标$t-1$或$t+1$),然后将$a_t$删去,下标$t$后面的数往前移$1$位。 最后问你有多少种方案可以使$c=b$题目描述
We start with a permutation $ a_1, a_2, \ldots, a_n $ and with an empty array $ b $ . We apply the following operation $ k $ times. On the $ i $ -th iteration, we select an index $ t_i $ ( $ 1 \le t_i \le n-i+1 $ ), remove $ a_{t_i} $ from the array, and append one of the numbers $ a_{t_i-1} $ or $ a_{t_i+1} $ (if $ t_i-1 $ or $ t_i+1 $ are within the array bounds) to the right end of the array $ b $ . Then we move elements $ a_{t_i+1}, \ldots, a_n $ to the left in order to fill in the empty space. You are given the initial permutation $ a_1, a_2, \ldots, a_n $ and the resulting array $ b_1, b_2, \ldots, b_k $ . All elements of an array $ b $ are distinct. Calculate the number of possible sequences of indices $ t_1, t_2, \ldots, t_k $ modulo $ 998\,244\,353 $ .输入输出格式
输入格式
Each test contains multiple test cases. The first line contains an integer $ t $ ( $ 1 \le t \le 100\,000 $ ), denoting the number of test cases, followed by a description of the test cases. The first line of each test case contains two integers $ n, k $ ( $ 1 \le k < n \le 200\,000 $ ): sizes of arrays $ a $ and $ b $ . The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le n $ ): elements of $ a $ . All elements of $ a $ are distinct. The third line of each test case contains $ k $ integers $ b_1, b_2, \ldots, b_k $ ( $ 1 \le b_i \le n $ ): elements of $ b $ . All elements of $ b $ are distinct. The sum of all $ n $ among all test cases is guaranteed to not exceed $ 200\,000 $ .
输出格式
For each test case print one integer: the number of possible sequences modulo $ 998\,244\,353 $ .
输入输出样例
输入样例 #1
3
5 3
1 2 3 4 5
3 2 5
4 3
4 3 2 1
4 3 1
7 4
1 4 7 3 6 2 5
3 2 4 5
输出样例 #1
2
0
4