#P10338. [THUSC 2019] 彩票
[THUSC 2019] 彩票
Problem Description
There is a lottery booth at Huaqing University, and it has lottery boxes. Initially, each box contains some tickets. Tickets are of two types: winning tickets and empty tickets. In box , there are winning tickets and empty tickets. Each time a student draws, they choose one box and then randomly draw one ticket from the remaining tickets in that box with equal probability, meaning every remaining ticket has the same probability of being drawn. Note that the drawn ticket is not put back into the box.
Now there are students waiting in line at the booth. They will act in order, and each student performs exactly one operation. Specifically, the student of the -th operation may do one of the following three actions:
- Draw: for every box from to , draw times consecutively from that box. If the number of remaining tickets in a box is less than , then draw all remaining tickets in that box.
- Query: for boxes from to , compute the expected value of the sum of the numbers of winning tickets that have been drawn.
- Add: in box , add winning tickets and empty tickets.
Please answer every query. By the nature of the problem, the expected value can always be written as a rational number of the form . You need to output its value modulo (a prime), i.e. find an such that . It can be proven that such an is unique.
Input Format
The first line contains two positive integers , representing the number of lottery boxes and the number of students.
The next lines each describe a box.
In the -th of these lines, there are two integers , with the meaning as described above.
The next lines each describe one student’s operation.
In the -th of these lines, the first integer indicates the operation type. If , then three integers follow. If , then two integers follow. If , then three integers follow. The meanings of the variables are as described above.
All integers on the same line are separated by one space.
The input guarantees:
.
.
.
.
.
.
Output Format
For each query with , output one line containing one integer representing the answer to the query.
3 6
1 2
2 2
2 0
1 1 1 1
1 2 2 1
2 1 3
3 3 1 1
1 3 3 3
2 1 3
833333340
83333337
Hint
Sample Explanation 1
After the first student’s operation, the expected number of winning tickets drawn from box 1 is .
After the second student’s operation, the expected number of winning tickets drawn from box 2 is .
So the third student’s answer is , and its value modulo is .
After the fourth student’s operation, box 3 has 3 winning tickets and 1 empty ticket.
After the fifth student’s operation, the expected number of winning tickets drawn from box 3 is .
So the sixth student’s answer is $\frac{1}{3} + \frac{1}{2} + \frac{9}{4} = \frac{37}{12}$, and its value modulo is .
Sample 2
See 2.in/2.ans in the problem attachments.
Sample 3
See 3.in/3.ans in the problem attachments.
Sample 4
See 4.in/4.ans in the problem attachments.
Subtasks
| Subtask ID | Score | Other Constraints | |
|---|---|---|---|
| 1 | 23 | and | |
| 2 | 17 | and | |
| 3 | 20 | ||
| 4 | |||
| 5 | None. |
Translated by ChatGPT 5