#P9149. 串串题
串串题
Problem Description
Given two integer sequences and of lengths and , and constants and , the sequences are indexed starting from . It is guaranteed that .
It is easy to see that there are ways to choose pairwise distinct integers from .
For each choice, we delete from all occurrences of the corresponding integers. Let the number of times sequence occurs in sequence at this time be the weight of this choice.
You need to compute the sum of the weights over all choices, modulo .
If you are unsure about the statement, please read the samples and the sample explanation.
Note: denotes a binomial coefficient, meaning the number of ways to choose items from items without order.
Please note: we will not delete the corresponding integers that appear in sequence .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases. For each test case:
The first line contains four positive integers , with .
The second line contains positive integers , representing sequence .
The third line contains positive integers , representing sequence .
Output Format
For each test case, output one integer: the answer modulo .
2
4 2 3 1
1 1 2 1
1 1
8 3 4 1
1 2 3 1 2 3 1 2
1 2 1
3
2
Hint
Sample Explanation
In the first test case of the sample:
- If we choose to delete the number from , then becomes , and the number of occurrences of in is .
- If we choose to delete the number from , then becomes , and the number of occurrences of in is .
- If we choose to delete the number from , then becomes , and the number of occurrences of in is .
Therefore, the answer for the first test case is .
Reminder again: we will not delete the corresponding integers that appear in sequence .
Constraints
For of the data, , , and .
This problem uses bundled testdata and enables subtask dependencies.
| Subtask | Special Property | Score | Dependency | |||
|---|---|---|---|---|---|---|
| 1 | \ | |||||
| 2 | Subtask 1 | |||||
| 3 | A | \ | ||||
| 4 | B | |||||
| 5 | Subtask 1, 2, 3, 4 | |||||
Special Property A: guaranteed that .
Special Property B: let be the total number of values that appear only in sequence but do not appear in sequence . It is guaranteed that .
Translated by ChatGPT 5