[Solution] PermutationForces II Codeforces Solution
You are given a permutation of length . Recall that permutation is an array consisting of distinct integers from to in arbitrary order.
You have a strength of and perform moves on the permutation . The -th move consists of the following:
- Pick two integers and such that , and swap the positions of the integers and in the permutation . Note that you can select in the operation, in which case no swap will occur.
You want to turn into another permutation after moves. However, some elements of are missing and are replaced with instead. Count the number of ways to replace each in with some integer from to so that is a permutation and it is possible to turn into with a strength of .
Since the answer can be large, output it modulo .
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers and (; ) — the size of the permutation and your strength, respectively.
The second line of each test case contains integers () — the elements of . All elements of are distinct.
The third line of each test case contains integers ( or ) — the elements of . All elements of that are not equal to are distinct.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the number of ways to fill up the permutation so that it is possible to turn into using a strength of , modulo .
No comments:
Post a Comment