#P7341. 『MdOI R4』Phoenix
『MdOI R4』Phoenix
Description
Given distinct sets , where all numbers in the sets are integers within the range .
Now you need to find how many permutations of satisfy
$$(\sum\limits_{i=1}^n |s_i|)-(\sum\limits_{i=1}^{n-1} |s_{p_i}\bigcap s_{p_{i+1}}|)=|\bigcup\limits_{i=1}^n s_i|$$The answer should be taken modulo . It is guaranteed that the real answer before taking modulo is greater than .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer indicating the number of test cases. For each test case:
The first line contains two positive integers .
The second line contains positive integers . Each positive integer represents a set under state compression. If the -th bit (from low to high) of in binary is , then contains ; otherwise, does not contain .
Output Format
Output lines, each corresponding to one test case.
For each test case, output one integer per line indicating the answer.
1
3 3
1 3 7
4
2
5 9
2 30 98 386 482
4 2
1 3 3 1
12
12
Hint
[Sample Explanation #1]
The three sets are .
There are permutations that satisfy the condition: .
[Constraints and Agreements]
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| No special restrictions | ||||
| No special restrictions | ||||
| No special restrictions | ||||
| Each set contains exactly two elements | ||||
| No special restrictions | ||||
| No special restrictions |
For of the testdata, , , , , where denotes the sum of over all test cases.
[Tips and Help]
The input size of this problem is large, so please choose a faster input method.
Thanks to for contributing to this problem.
Translated by ChatGPT 5
京公网安备 11011102002149号