CF1442B.Identify the Operations
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We start with a permutation a1,a2,…,an and with an empty array b . We apply the following operation k times.
On the i -th iteration, we select an index ti ( 1≤ti≤n−i+1 ), remove ati from the array, and append one of the numbers ati−1 or ati+1 (if ti−1 or ti+1 are within the array bounds) to the right end of the array b . Then we move elements ati+1,…,an to the left in order to fill in the empty space.
You are given the initial permutation a1,a2,…,an and the resulting array b1,b2,…,bk . All elements of an array b are distinct. Calculate the number of possible sequences of indices t1,t2,…,tk modulo 998244353 .
输入格式
Each test contains multiple test cases. The first line contains an integer t ( 1≤t≤100000 ), 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≤k<n≤200000 ): sizes of arrays a and b .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤n ): elements of a . All elements of a are distinct.
The third line of each test case contains k integers b1,b2,…,bk ( 1≤bi≤n ): elements of b . All elements of b are distinct.
The sum of all n among all test cases is guaranteed to not exceed 200000 .
输出格式
For each test case print one integer: the number of possible sequences modulo 998244353 .
输入输出样例
输入#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
说明/提示
\require{cancel}
Let's denote as a1a2…aiai+1…an→a1a2…ai−1ai+1…an−1 an operation over an element with index i : removal of element ai from array a and appending element ai+1 to array b .
In the first example test, the following two options can be used to produce the given array b :
- 12345→1235→125→12 ; (t1,t2,t3)=(4,3,2) ;
- 12345→1235→235→15 ; (t1,t2,t3)=(4,1,2) .
In the second example test, it is impossible to achieve the given array no matter the operations used. That's because, on the first application, we removed the element next to 4 , namely number 3 , which means that it couldn't be added to array b on the second step.
In the third example test, there are four options to achieve the given array b :
- 1473625→143625→14325→4325→435 ;
- 1473625→143625→14325→1425→145 ;
- 1473625→147325→14725→4725→475 ;
- 1473625→147325→14725→1425→145 ;