#P10338. Lottery Ticket Drawing Simulation

    ID: 12342 Type: Default 1000ms 256MiB

Lottery Ticket Drawing Simulation

Lottery Ticket Drawing Simulation

There is a lottery station at Huaqing University which has n lottery boxes. Initially, the i-th box contains ai winning tickets and bi blank tickets. When a student performs a draw from a box, a ticket is randomly selected from the box (each remaining ticket is equally likely to be chosen) and is not replaced.

There are m operations performed sequentially by students. Each operation can be one of the following three types:

  1. Draw: Given indices l and r and an integer c, for every box from box l to box r (inclusive), perform c consecutive draws. If the number of remaining tickets in a box is less than c, draw all the remaining tickets from that box. For a box with W winning tickets and T total tickets, if d = min(c, T) tickets are drawn, the expected number of winning tickets drawn is:</p>

    \(\displaystyle E = \frac{d \times W}{T}\)

    After the draw, the state of that box is updated as follows (using expectation):

    \(\displaystyle W' = W \times \frac{T-d}{T},\quad T' = T-d\)

    1. Query: Given indices x and y, report the expected total number of winning tickets drawn from boxes x through y (inclusive). Note that the expected drawn winning tickets from a box equals the total number of winning tickets that have ever been in the box (initial winning tickets plus those added later) minus the current expected winning tickets remaining in the box.
    2. Add Tickets: For a given index p, add u winning tickets and v blank tickets to the p-th box. This increases the total winning tickets erroneously available in that box by u and the total ticket count by u+v.

    It is known that each query answer can be represented as a rational number \(\frac{p}{q}\). Output an integer r (with \(0 \le r < 10^9+7\)) such that:

    \(\displaystyle q \times r \equiv p \pmod{10^9+7}\)

    You may assume that such an r exists and is unique.

    inputFormat

    The first line contains two integers n and m \((1 \leq n, m \leq \text{small})\)---the number of boxes and the number of operations, respectively.

    The second line contains n integers \(a_1, a_2, \dots, a_n\) \( (0 \le a_i \le 10^9)\) representing the number of winning tickets in each box initially.

    The third line contains n integers \(b_1, b_2, \dots, b_n\) \( (0 \le b_i \le 10^9)\) representing the number of blank tickets in each box initially.

    The following m lines each describe an operation. Each operation starts with an integer indicating its type:

    • If the type is 1 (Draw), the line contains: 1 l r c
    • If the type is 2 (Query), the line contains: 2 x y
    • If the type is 3 (Add Tickets), the line contains: 3 p u v

    Note that all indices are 1-indexed.

    outputFormat

    For each Query operation (type 2), output the answer on a separate line. The answer should be the integer r such that if the expected answer is \(\frac{p}{q}\), then \(q \times r \equiv p\) mod \(10^9+7\).

    sample

    3 5
    3 0 5
    2 4 1
    2 1 3
    1 1 2 2
    2 1 2
    3 3 4 1
    2 3 3
    0
    

    400000004 0

    </p>