Under construction

Still being built. Things may change

Infinitely Bursting Bubbles in a Glass Bottle

Time limit3sMemory limit1024 MB

Summary
Simulate bubbles across N zones over T seconds, adding bubbles to a given zone then spreading them up and down, and print the total each second.
Level

Medium6 of 10

Topics
Simulation, Array, Segment tree
Solved
No attempts yet

Problem

너에게서는 멸종된 과일 향기가 난다

투룸 신축 빌라 보증금 이천에 월세 구십, 어떻게 해야 너를 웃길 수 있을까 하는 생각, 두 시간 동안의 폭우, 일주일 동안의 아침, 유리병 속 무한히 터지는 기포

-고선경, [샤워젤과 소다수]

A tall, thin glass bottle stands upright. Inside it, bubbles burst endlessly.

Scientist Jeongwoo became curious about this phenomenon and kept observing it. He found the following facts. First, divide the bottle vertically into NN equal parts, forming NN zones from zone 11 at the bottom to zone NN at the top. Each zone can hold at most MM bubbles. At the start, no zone has any bubbles. Every second, the following two phenomena occur in turn, in this order.

  • Bubble creation: Bubbles are created in one zone of the bottle. At the ii-th creation, kik_i bubbles are created in zone yiy_i. If the sum of the bubbles already in that zone and the newly created bubbles exceeds MM, only MM bubbles remain and the rest disappear.
  • Bubble movement: Bubbles in all zones move up or down at the same time. If zone ii has aia_i bubbles, then ⌊ai5⌋\left\lfloor\frac{a_i}{5}\right\rfloor bubbles move to the zone directly above, ⌊ai5⌋\left\lfloor\frac{a_i}{5}\right\rfloor bubbles move to the zone directly below, ⌊ai5⌋\left\lfloor\frac{a_i}{5}\right\rfloor bubbles stay in place, and the remaining bubbles disappear. A bubble that tries to move below zone 11 or above zone NN disappears. After movement, if any zone has more than MM bubbles, only MM remain and the rest disappear.

Figure 1. (a) The bottle divided into NN zones. (b) Bubble movement at zone 11 and zone NN.

Jeongwoo wants to write a program that models how bubbles move in the bottle. Let S(t)S(t) be the total number of bubbles left in the bottle after tt seconds, that is, after tt rounds of bubble creation and bubble movement. Given the observation time TT, find the values of S(1),S(2),⋯ ,S(T)S(1), S(2), \cdots, S(T).

Input

The first line contains three integers NN, MM, and TT, separated by spaces: the number of zones, the maximum number of bubbles each zone can hold, and the observation time. (1≤N≤100 0001 \leq N \leq 100\,000, 1≤M≤100 0001 \leq M \leq 100\,000, 1≤T≤50 0001 \leq T \leq 50\,000)

From the second line onward, the next TT lines each contain, for the ii-th creation, the zone number yiy_i where bubbles are created and the number of bubbles kik_i created there, separated by a space. (1≤yi≤N1 \leq y_i \leq N, 0≤ki≤M0 \leq k_i \leq M)

Output

Print TT lines. On line ii, print S(i)S(i).

Hint

⌊x⌋\lfloor x \rfloor is the floor function, which gives the largest integer less than or equal to the real number xx.

Examples2

  1. Example 1

    Input
    6 100 6
    3 20
    2 40
    4 60
    3 80
    1 100
    5 100
    
    Expected output
    12
    24
    44
    66
    73
    92
    
  2. Example 2

    Input
    6 100 2
    1 100
    1 100
    
    Expected output
    40
    52