#P15863. [LBA-OI R3 C] wywmrfz
[LBA-OI R3 C] wywmrfz
Description
Little Y has recently become obsessed with a tower defense game.
Today, she focuses on a character, Little W. Little W can block at most 2 enemies at the same time and perform several attacks. Each attack can be one of two types:
- Normal attack: Deals 1 damage to all blocked enemies simultaneously.
- Critical strike: Deals 2 damage to all blocked enemies simultaneously.
Now, Little Y gives Little W tasks. In each task, Little W needs to attack exactly times to defeat enemies. The -th enemy has health and must be defeated within the -th to -th attacks. Little Y will not make it too hard: Little W never needs to face 3 or more enemies at once.
Little Y wants to know: how many valid attack sequences satisfy all requirements? Since the answer can be huge, you only need to output it modulo .
Two attack sequences are different if there exists an such that one sequence uses a normal attack on the -th step and the other uses a critical strike.
Formal Statement
Given positive integers and triples , a sequence is called good if and only if:
- All elements are in .
- For every , .
You need to find the number of good sequences modulo .
Guarantee: Every position is covered by at most 2 intervals, i.e.
$$\forall i\in[1,n],\; \sum\limits_{j=1}^m \left[\,i\in[l_j,r_j]\,\right] \le 2$$There are test cases in one test point.
Input Format
The first line contains an integer , the number of tasks.
For each test case:
- The first line contains two integers .
- The next lines each contain three integers , representing the information of an enemy.
Output Format
Output lines. Each line contains one integer: the answer for the -th test case modulo .
3
5 2
1 4 7
2 5 7
10 3
3 3 1
3 4 2
7 9 4
5000 6
1657 2689 1560
2 1789 2643
1790 3701 2878
1360 1655 429
2692 3856 1744
3 1357 2010
4
96
952912621
Hint
Data Constraints
| Test Case | Special Property | ||
|---|---|---|---|
| None | |||
| Yes | |||
| None | |||
Special Property: Every position is covered by at most 1 interval: $\forall i\in[1,n],\; \sum\limits_{j=1}^m \left[\,i\in[l_j,r_j]\,\right] \le 1$.
For data: .
Hard Guarantee: $\forall i\in[1,n],\; \sum\limits_{j=1}^m \left[\,i\in[l_j,r_j]\,\right] \le 2$.
京公网安备 11011102002149号