#P10338. [THUSC 2019] 彩票

[THUSC 2019] 彩票

Problem Description

There is a lottery booth at Huaqing University, and it has nn lottery boxes. Initially, each box contains some tickets. Tickets are of two types: winning tickets and empty tickets. In box ii, there are aia_i winning tickets and bib_i 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 mm students waiting in line at the booth. They will act in order, and each student performs exactly one operation. Specifically, the student of the jj-th operation may do one of the following three actions:

  1. Draw: for every box from ljl_j to rjr_j, draw cjc_j times consecutively from that box. If the number of remaining tickets in a box is less than cjc_j, then draw all remaining tickets in that box.
  2. Query: for boxes from xjx_j to yjy_j, compute the expected value of the sum of the numbers of winning tickets that have been drawn.
  3. Add: in box pjp_j, add uju_j winning tickets and vjv_j 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 pq\frac{p}{q}. You need to output its value modulo 109+710^9+7 (a prime), i.e. find an rr (0r<109+7)(0\leq r < 10^9+7) such that qrp(mod109+7)qr \equiv p \pmod{10^9+7}. It can be proven that such an rr is unique.

Input Format

The first line contains two positive integers n,mn,m, representing the number of lottery boxes and the number of students.

The next nn lines each describe a box.

In the ii-th of these nn lines, there are two integers ai,bia_i,b_i, with the meaning as described above.

The next mm lines each describe one student’s operation.

In the jj-th of these mm lines, the first integer opjop_j indicates the operation type. If opj=1op_j=1, then three integers lj,rj,cjl_j,r_j,c_j follow. If opj=2op_j=2, then two integers xj,yjx_j,y_j follow. If opj=3op_j=3, then three integers pj,uj,vjp_j,u_j,v_j follow. The meanings of the variables are as described above.

All integers on the same line are separated by one space.

The input guarantees:

0ai,bi,cj1080 \leq a_i,b_i,c_j \leq 10^8.

0uj,vj1030\leq u_j,v_j \leq 10^3.

1ljrjn1\leq l_j\leq r_j \leq n.

1xjyjn1\leq x_j\leq y_j\leq n.

1pjn1\leq p_j\leq n.

opj{1,2,3}op_j \in \{1,2,3\}.

Output Format

For each query with opj=2op_j = 2, 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 13\frac{1}{3}.

After the second student’s operation, the expected number of winning tickets drawn from box 2 is 12\frac{1}{2}.

So the third student’s answer is 13+12=56\frac{1}{3} + \frac{1}{2} = \frac{5}{6}, and its value modulo 109+710^9+7 is 833333340833333340.

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 94\frac{9}{4}.

So the sixth student’s answer is $\frac{1}{3} + \frac{1}{2} + \frac{9}{4} = \frac{37}{12}$, and its value modulo 109+710^9+7 is 8333333783333337.

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 n,mn,m\leq Other Constraints
1 23 10001000 0ai,bi100\leq a_i,b_i \leq 10 and opj3op_j \neq 3
2 17 10510^5 opj3op_j \neq 3 and lj=rjl_j = r_j
3 20 2×1052 \times 10^5 lj=rjl_j=r_j
4 opj3op_j \neq 3
5 3×1053 \times 10^5 None.

Translated by ChatGPT 5