#P9821. Out of Control
Out of Control
Out of Control
Problem Description
There is a cloud service API to help user store history timestamps. The data structure for each user is initially an empty stack. Every time you post a request to the API with an integer , denoting the current timestamp, the service will append to the end of the stack. When is less than the previous timestamp stored in the stack, the service will think the input is wrong, and will append the previous timestamp instead of . You have posted the API for times, your request timestamp is in the -th call. However, the network is out of control. The service may receive your requests in any arbitrary order, and may even miss some requests. Knowing this issue, you are asking for the on-call engineer to have a look at your stack in the database. Assume the service received exactly requests, how many possible distinct stacks will it be?
Input
The first line contains a single integer (), the number of test cases. For each test case: The first line of the input contains a single integer (), denoting the total number of requests. The second line contains integers (), denoting the timestamp of each request. It is guaranteed that the sum of all is at most .
Output
For each test case, output lines, the -th () of which containing an integer, denoting the number of distinct stacks when . Note that the answer may be extremely large, so please print it modulo instead.
Sample Input
2
3
1 2 3
3
2 3 3
Sample Output
3
5
5
2
2
2
Hint
In the first example:
- When , the stack can be , or .
- When , the stack can be , , , or .
- When , the stack can be , , , or . In the second example:
- When , the stack can be or .
- When , the stack can be or .
- When , the stack can be or .
Source
2023“钉耙编程”中国大学生算法设计超级联赛(3)