#P7483. 50 年后的我们
50 年后的我们
Background
YSGHYYDS.
Problem Description
YSGH prepared problems for a contest. The difficulty of problem is , and its value is .
There are potential contestants. Contestant participates in the contest with probability . If contestant participates, then they will solve exactly all problems whose difficulties are between and (including and ).
The contest committee will finally award YSGH a bonus equal to the -th power of the sum of values of all problems that are solved by at least one contestant. In particular, we define .
You need to help YSGH compute the expected value of the bonus.
Let . Suppose a rational number is written in lowest terms as . If , then there exists a unique integer () such that . We call this the value of modulo .
It can be proven that even if only the value of modulo is given, the answer still exists uniquely modulo .
Input Format
The first line contains three integers , representing the number of problems, the number of potential contestants, and the parameter used to compute the bonus.
The next lines each contain two integers , representing the difficulty and value of problem .
The next lines each contain three integers , representing the difficulty interval of problems that contestant can solve, and the probability (given modulo ) that they participate in the contest.
Output Format
Output one line with one integer, representing the expected value of the bonus modulo .
5 2 1
346 412
464 685
895 544
976 322
612 121
346 712 2
850 932 3
4068
5 2 2
346 412
464 685
895 544
976 322
612 121
233 749 798465123
698 985 151455772
105133973
Hint
Sample Explanation #1
This sample satisfies Special Property A.
If the first person participates, they can solve problems .
If the second person participates, they can solve problem .
So the expected bonus of YSGH is $(412+685+121)\times 2\times (1-3)+544\times (1-2)\times 3+(412+685+121+544)\times 2\times 3\equiv 4068\pmod{P}$.
Constraints
This problem uses bundled testdata.
For of the testdata, , , , , , .
The special constraints and scores of each Subtask are as follows:
| Test Package ID | Other Constraints | Score | ||
|---|---|---|---|---|
| Special Property A | ||||
| None | ||||
| Special Property A | ||||
| None | ||||
| Special Property A | ||||
| None | ||||
| Special Property A | ||||
| None | ||||
| Special Property A | ||||
| None | ||||
Special Property A: For any , we have .
Translated by ChatGPT 5