#P5324. [BJOI2019] 删数

    ID: 4266 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2019线段树各省省选北京O2优化Link-Cut Tree,LCT

[BJOI2019] 删数

Description

For any sequence, if it can be deleted into an empty sequence after performing the following delete operation a finite number of times, then the sequence is said to be deletable to empty.

One delete operation is defined as follows:

Let the current sequence length be kk. Then delete all numbers in the sequence that are equal to kk.

Now there is a sequence aa of length nn, and there are mm modification operations. After the ii-th modification, you need to answer: For the sequence aa after ii modifications, what is the minimum number of elements that still need to be changed so that it can be deleted to empty?

Each modification is either a point update, or adding 11 to the whole sequence, or subtracting 11 from the whole sequence.

Input Format

The first line contains two positive integers n,mn, m, representing the sequence length and the number of modifications.

The second line contains nn positive integers, representing the sequence aa. That is, the ii-th input number is the ii-th element of the sequence, aia_i.

The next mm lines each contain two integers p,xp, x, representing one modification operation. When 1pn1 \le p \le n, this operation is a point update: set the pp-th number in the sequence, apa_p, to xx. When p=0p = 0, this operation adds xx to the whole sequence.

Output Format

Output mm lines, each containing one integer. The ii-th line denotes the answer after the first ii modifications.

3 9
1 2 3
1 1
0 1
0 1
0 1
2 2
3 2
0 -1
0 -1
0 -1
0
1
2
3
2
1
1
2
2

Hint

Sample Explanation (partial): After the first modification, the sequence is (1,2,3)(1, 2, 3), and it can be deleted to empty without any changes. After the fourth modification, the sequence is (4,5,6)(4, 5, 6), and all three numbers must be changed before it can possibly be deleted to empty. After the sixth modification, the sequence is (4,2,2)(4, 2, 2), and changing the first number to 33 makes it deletable to empty. After the ninth modification, the sequence is (1,1,1)(1, -1, -1), and you can change the second number to 22 and the third number to 33 to make it deletable to empty.

Constraints: For 100%100\% of the testdata:

  • 1n,m1500001 \le n, m \le 150000, 1ain1 \le a_i \le n, 0pn0 \le p \le n.
  • When p>0p > 0, 1xn1 \le x \le n.
  • When p=0p = 0, x{1,1}x \in \{-1, 1\}.

Translated by ChatGPT 5