This page is still under construction.

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

Lamb's Respite

Time limit3sMemory limit1024 MB

Summary
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 hh, and the maximum health HH. If a champion's health is less than or equal to zero (h≤0h \le 0), the champion dies and leaves the game immediately with h=0h = 0. If a champion's health is above the maximum health (h>Hh > H), then it is adjusted to its maximum health. HH 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 nn actions. The ii-th (1≤i≤n1 \le i \le n) action increases the health of the champion by aia_i, subject to the rules above. If aia_i is positive, it means the champion was healed. If aia_i is negative, it means the champion was attacked. If aia_i 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 HH. If Wookje activates Lamb's Respite from right before the ll-th action until right after the rr-th action, a champion's health will never fall below ⌈H10⌉\lceil \frac{H}{10} \rceil during these actions. If a champion's health was less than or equal to ⌈H10⌉\lceil \frac{H}{10} \rceil right before the ll-th action, or would hypothetically be less than or equal to ⌈H10⌉\lceil \frac{H}{10} \rceil after the ii-th action for some l≤i≤rl \le i \le r, then its health is set to ⌈H10⌉\lceil \frac{H}{10} \rceil and does not change any further until after the rr-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 qq queries:

  • 1 l r x: The champion's maximum health is xx, and its health starts at xx. Lamb's Respite is active from right before the ll-th action to right after the rr-th action. Output the health of the champion after the nn actions. If the champion dies, output 00. (1≤l≤r≤n,1≤x≤109)(1 \le l \le r \le n, 1 \le x \le 10^9).
  • 2 i x: Update aia_i to xx. (1≤i≤n,−109≤x≤109)(1 \le i \le n, -10^9 \le x \le 10^9).

Input

The first line contains two integers, nn and q (1≤n,q≤300 000)q\ (1 \le n, q \le 300\,000).

The second line contains nn integers. The ii-th integer is ai (∣ai∣≤109)a_i\ (|a_i| \le 10^9).

The next qq lines contain several integers denoting the queries in the described form.

There is at least 11 query of type 11.

Output

For each query of type 11, output a single integer denoting the answer to that query. Each answer should go on its own line.

Examples2

  1. Example 1

    Input
    4 10
    0 1 1 -1
    1 2 4 2
    2 2 -1
    1 2 4 2
    1 2 3 2
    2 1 -1
    1 1 4 2
    1 2 4 2
    2 1 -2
    1 1 4 2
    1 2 4 2
    
    Expected output
    1
    1
    0
    1
    1
    1
    0
    
  2. Example 2

    Input
    6 6
    2 5 -3 8 1 -4
    1 2 5 7
    1 1 3 2
    2 2 -1
    1 4 6 2
    2 1 -1
    1 1 6 6
    
    Expected output
    3
    0
    0
    1