This page is still under construction.

Parts of this page are still being built. What you see may change.

The Strange Galton Board

Time limit1sMemory limit1024 MB

Summary
A Galton board where a marble from each starting peg lands uniformly on its reachable bottom slots. Process drop queries, then answer range-sum expectation queries on the destination line.
Level

Medium6 of 10

Topics
Math, Combinatorics, Prefix sum, Implementation
Solved
No attempts yet

Problem

Francis Galton invented the Galton board to demonstrate the central limit theorem: that for a large enough sample size, the binomial distribution approaches the normal distribution. A Galton board consists of a board with pegs set perpendicular to it. When a marble is dropped from the top, it repeatedly hits rows of pegs and bounces either left or right. Marbles that reach the bottom are separated by partitions, and an ordinary Galton board shows a normal distribution as in the figure above. In the strange Galton board of the strange land, however, a marble lands on every destination reachable from its starting point with equal probability. Because a similar number of marbles at every destination would be boring, the starting point from which the marble is dropped can be chosen.

For a strange Galton board of height 5, the numbering of starting points and destinations follows the rule shown above.

If a marble is dropped from starting point 2, it reaches every destination in [1, 5] with equal probability. If it is dropped from starting point 6, it reaches every destination in [3, 6] with equal probability.

Alice of the strange land dropped marbles onto the strange Galton board and tried to count the marbles at the destinations, but there were too many and she gave up. Instead she wants to estimate the counts by computing the expected number of marbles at the destinations. Help Alice by writing a program that outputs the expected values of the marbles.

The program performs two kinds of queries.

QQ queries that drop marbles are given.

aa, bb: bb marbles are dropped from the aa-th starting point.

After all marbles have been dropped, RR queries ask for the expected number of marbles at the destinations.

a,ba, b: Output the expected number of marbles that land on destinations [a,ba, b].

The program terminates after processing all expectation queries.

Input

The first line gives the height HH. (1≤H≤100,0001 \le H \le 100,000)

The second line gives the number of marble-dropping queries QQ and the number of expectation queries RR. (1≤Q≤100,0001 \le Q \le 100,000, 1≤R≤100,0001 \le R \le 100,000)

Starting from the third line, QQ queries a,ba, b are given. (1≤a≤H(H+1)21 \le a \le \frac{H(H + 1)}{2}, 1≤b≤100,0001 \le b \le 100,000)

Starting from line 3 + QQ, RR queries aa, bb are given. (1≤a≤b≤H+11 \le a \le b \le H + 1)

Output

Output the result of each query in order, one per line.

Absolute or relative error up to 10−410^{-4} is allowed.

Examples1

  1. Example 1

    Input
    5
    2 3
    2 15
    6 12
    1 2
    3 5
    6 6
    
    Expected output
    6.0
    18.0
    3.0