Magic Orbs
Time limit1sMemory limit1024 MB
Orbs dropped on zone 1 roll right past strictly lower zones and raise the zone where they stop; report zone 1's value after each batch.
- Level
Hard8 of 10
- Topics
- Array, Simulation, Math
- Solved
- No attempts yet
Problem
zones are arranged in a straight line. The zones are numbered from left to right, and the initial value of zone is .
A magic orb raises the values of zones. When an orb is dropped on zone 1, it behaves as follows.
- Let be the zone where the orb currently sits. If and the value of zone is lower than the value of zone , the orb moves to zone . Repeat this until the orb stops moving.
- If the orb does not move from zone , add to the value of that zone.
A wizard left you tasks of two kinds, to be processed in order. All results accumulate. At least one task asks for the value of zone 1.
- 1 x: Drop orbs onto zone 1, one at a time. Each orb finishes its movement and increases the value of the zone where it stops. Only then is the next orb dropped.
- 2: Print the value of zone 1.
Input
The first line contains and , separated by a space.
The second line contains the initial values , separated by spaces.
Each of the next lines contains one task.
Output
For each task of type 2, print the value of zone 1 on its own line.
Constraints
- All given numbers are integers.
- for
- At least one task asks for the value of zone 1.