Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022
While searching for the pizza, baby Hosssam came across two permutations and of length .
Recall that a permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
Baby Hosssam forgot about the pizza and started playing around with the two permutations. While he was playing with them, some elements of the first permutation got mixed up with some elements of the second permutation, and to his surprise those elements also formed a permutation of size .
Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022
Dorms War Codeforces Solution | Codeforces Problem Solution 2022
Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022
Very Suspicious Codeforces Solution | Codeforces Problem Solution 2022
Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022
Jee, You See? Codeforces Solution | Codeforces Problem Solution 2022
Specifically, he mixed up the permutations to form a new array in the following way.
- For each (), he either made or .
- The array is a permutation.
You know permutations , , and values at some positions in . Please count the number different permutations that are consistent with the described process and the given values. Since the answer can be large, print it modulo .
It is guaranteed that there exists at least one permutation that satisfies all the requirements.
The first line contains an integer () — the number of test cases.
The first line of each test case contains a single integer () — the length of the permutations.
The next line contains distinct integers () — the first permutation.
The next line contains distinct integers () — the second permutation.
The next line contains distinct integers ( is either , , or ) — the description of the known values of . If , then there are no requirements on the value of . Otherwise, it is required that .
It is guaranteed that there exists at least one permutation that satisfies all the requirements.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print the number of possible permutations , modulo .
Join Now for Solution:-
No comments:
Post a Comment