#P12263. 『STA - R9』回听

『STA - R9』回听

Problem Description

Given a sequence aa of length nn, define the playback operation as follows:

Define one playback operation as: choose any x[1,n]x\in [1,n], and then perform the following operation any number of times (possibly 00 times):

  • axmax{ax1,0}a_x \leftarrow \max\{a_x-1,0\}, choose a j[1,x)j\in[1,x), swap ax,aja_x,a_j, and set xjx \leftarrow j.

Let bib_i be the minimum possible value of aia_i after performing one playback operation.

Note that the playback operation does not actually affect the values of the sequence aa. You may assume that after the operation, aa returns to the state before the operation.

The sequence will undergo mm modification operations. Each time, given l,r,vl,r,v, increase every number from ala_l to ara_r by vv. After each modification, you need to output how many essentially different bib_i there are after performing one playback operation (two values bib_i and bjb_j are essentially different if and only if bibjb_i \ne b_j).

Note: modification operations affect each other, while playback operations are independent of each other.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers, where the ii-th integer represents aia_i.

The next mm lines each contain 33 integers, representing l,r,vl,r,v.

Output Format

Output mm lines. Each line contains one integer, representing the number of essentially different bib_i.

3 1
2 2 2
2 3 1
2
4 3
6 5 6 6
3 3 1
1 3 2
4 4 5
3
4
2

Hint

[Operation Explanation]

For the sequence {3,8,2,4,7}\{3,8,2,4,7\}, the playback operation proceeds as follows:

If we choose x=5x=5 and perform 33 operations, with chosen jj being 4,2,14,2,1 respectively, then the entire sequence changes as:

  • {3,8,2,4,7}\{3,8,2,4,7\}
  • {3,8,2,6,4}\{3,8,2,6,4\}
  • {3,5,2,8,4}\{3,5,2,8,4\}
  • {4,3,2,8,4}\{4,3,2,8,4\}

[Sample 11 Explanation]

After the modification operation, the sequence aa becomes {2,3,3}\{ 2,3,3\}.

When i=1i=1, choose x=3x=3, perform 22 operations, and choose jj as 2,12,1 respectively, obtaining bi=a311=1b_i=a_3-1-1=1.

When i=2i=2, choose x=2x=2, perform 11 operation, choose j=1j =1, obtaining bi=a1=2b_i=a_1=2.

When i=3i=3, choose x=3x=3, perform 11 operation, choose j=1j =1, obtaining bi=a1=2b_i=a_1=2.

Therefore, the sequence bb is {1,2,2}\{ 1,2,2\}, so the answer is 22.

[Constraints]

This problem uses bundled testdata.

  • Subtask 0 (10 pts): 1n,m101\le n,m \le 10.
  • Subtask 1 (15 pts): 1n,m1051\le n,m \le 10^5, l2l\ge 2, a1=1a_1=1, i[2,n],ai>i\forall i\in[2,n],\,a_i>i.
  • Subtask 2 (15 pts): 1n,m10001\le n,m \le 1000.
  • Subtask 3 (30 pts): 1n,m1051\le n,m \le 10^5.
  • Subtask 4 (30 pts): no special constraints.

For all testdata, it is guaranteed that 1n,m5×1051\le n,m\le 5\times10^5, 1ai,v1061\le a_i,v\le 10^6, 1lrn1\le l\le r\le n.

The input/output size of this problem is large. It is recommended to use fast IO methods.

Translated by ChatGPT 5