Under construction

Still being built. Things may change

Heavy rain (Easy)

Time limit2sMemory limit1024 MB

Summary
Given N walls with heights, print the total rain that can be trapped after each of Q updates that raise one wall's height.
Level

Medium6 of 10

Topics
Array, Segment tree
Solved
No attempts yet

Problem

Rain falls endlessly on NN cells in a row. Initially, cell ii has a wall of height AiA_i. When the water trapped inside a wall fills up, it overflows past the left and right ends and disappears. Rain does not move in any direction other than left and right along the row.

There are QQ queries. Each query consists of ii and xx, meaning that from then on, the wall in cell ii has height xx. It is guaranteed that Ai<xA_i < x.

After each query, print the maximum amount of rain that can end up collecting.

Input

The first line contains NN and QQ in that order (1≤N≤100 0001 \le N \le 100\,000; 1≤Q≤100 0001 \le Q \le 100\,000).

The second line contains the initial heights A1,A2,…,ANA_1, A_2, \ldots, A_N in order (1≤Ai≤1091 \le A_i \le 10^9).

Each of the next QQ lines contains two integers ii and xx, separated by a space (1≤i≤N1 \le i \le N; 1≤x≤1091 \le x \le 10^9).

All numbers in the input are integers.

Output

Print QQ lines. The kk-th line is the answer after the kk-th query.

Examples1

  1. Example 1

    Input
    12 3
    3 1 4 1 5 9 2 6 5 3 5 10
    4 2
    1 10
    3 9
    
    Expected output
    28
    58
    53