Lamb's Respite
Time limit3sMemory limit1024 MB
For each query, a champion starts at health x with Lamb's Respite clamping health to ceil(x/10) during actions l..r; report final health after all n actions, with point updates to a_i.
- Level
Hard9 of 10
- Topics
- Segment tree, Implementation, Binary search, Math
- Solved
- No attempts yet
Problem
Wookje is playing the game League of Legends, where two teams of players fight against each other. Each player manages a champion whose status can be represented by two integers: the health , and the maximum health . If a champion's health is less than or equal to zero (), the champion dies and leaves the game immediately with . If a champion's health is above the maximum health (), then it is adjusted to its maximum health. will always be a positive integer.
In a teamfight, the health of the champion may increase or decrease. More specifically, during a teamfight, the champion was subject to actions. The -th () action increases the health of the champion by , subject to the rules above. If is positive, it means the champion was healed. If is negative, it means the champion was attacked. If is zero, then nothing happened to the champion.
Wookje's favorite champion in League of Legends is a lamb named Kindred. Kindred has a ultimate ability named Lamb's Respite. Let's see what this ability does.

Formally, consider a champion with maximum health . If Wookje activates Lamb's Respite from right before the -th action until right after the -th action, a champion's health will never fall below during these actions. If a champion's health was less than or equal to right before the -th action, or would hypothetically be less than or equal to after the -th action for some , then its health is set to and does not change any further until after the -th action completes. Otherwise, Lamb's Respite does not affect how the champion's health changes.
It is very important to make the right decision on when to activate Lamb's Respite. Wookje wants to improve his decision-making skills. However, the teamfights are too complicated, therefore it's hard for him to know when to activate Lamb's Respite. To help him, please process the following queries:
1 l r x: The champion's maximum health is , and its health starts at . Lamb's Respite is active from right before the -th action to right after the -th action. Output the health of the champion after the actions. If the champion dies, output . .2 i x: Update to . .
Input
The first line contains two integers, and .
The second line contains integers. The -th integer is .
The next lines contain several integers denoting the queries in the described form.
There is at least query of type .
Output
For each query of type , output a single integer denoting the answer to that query. Each answer should go on its own line.