CF2007B.Index and Maximum Value

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Index and Maximum Value

After receiving yet another integer array a1,a2,,ana_1, a_2, \ldots, a_n at her birthday party, Index decides to perform some operations on it.

Formally, there are mm operations that she is going to perform in order. Each of them belongs to one of the two types:

  • + l r. Given two integers ll and rr, for all 1in1 \leq i \leq n such that lairl \leq a_i \leq r, set ai:=ai+1a_i := a_i + 1.
  • - l r. Given two integers ll and rr, for all 1in1 \leq i \leq n such that lairl \leq a_i \leq r, set ai:=ai1a_i := a_i - 1.

For example, if the initial array a=[7,1,3,4,3]a = [7, 1, 3, 4, 3], after performing the operation +pace2pace4\texttt{+} pace 2 pace 4, the array a=[7,1,4,5,4]a = [7, 1, 4, 5, 4]. Then, after performing the operation -pace1pace10\texttt{-} pace 1 pace 10, the array a=[6,0,3,4,3]a = [6, 0, 3, 4, 3].

Index is curious about the maximum value in the array aa. Please help her find it after each of the mm operations.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t21041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n1051 \leq n \leq 10^5, 1m1051 \leq m \leq 10^5) — the length of the array and the number of operations.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — the initial array aa.

Then mm lines follow, each line corresponds to the operation, in the following format: c l r (c{+,-}c \in \{\texttt +, \texttt -\}, ll and rr are integers, 1lr1091 \leq l \leq r \leq 10^9) — the description of the operation.

Note that the elements aia_i may not satisfy 1ai1091\le a_i\le 10^9 after some operations, as it is shown in the example.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5, and the sum of mm over all test cases does not exceed 10510^5.

Output

For each test case, output one single line containing mm integers, with the ii-th of them describing the maximum value of the array after the ii-th operation.

Note

In the first test case, the process of the operations is listed below:

  • After the first operation, the array becomes equal [2,3,4,3,2][2,3,4,3,2]. The maximum value is 44.
  • After the second operation, the array becomes equal [1,2,4,2,1][1,2,4,2,1]. The maximum value is 44.
  • After the third operation, the array becomes equal [2,3,4,3,2][2,3,4,3,2]. The maximum value is 44.
  • After the fourth operation, the array becomes equal [3,4,5,4,3][3,4,5,4,3]. The maximum value is 55.
  • After the fifth operation, the array becomes equal [3,4,5,4,3][3,4,5,4,3]. The maximum value is 55.

In the second test case, the process of the operations is listed below:

  • After the first operation, the array becomes equal [2,4,4,5,5][2,4,4,5,5]. The maximum value is 55.
  • After the second operation, the array becomes equal [3,4,4,5,5][3,4,4,5,5]. The maximum value is 55.
  • After the third operation, the array becomes equal [3,3,3,4,4][3,3,3,4,4]. The maximum value is 44.
  • After the fourth operation, the array becomes equal [2,2,2,4,4][2,2,2,4,4]. The maximum value is 44.
  • After the fifth operation, the array becomes equal [1,1,1,3,3][1,1,1,3,3]. The maximum value is 33.

Samples

5
5 5
1 2 3 2 1
+ 1 3
- 2 3
+ 1 2
+ 2 4
- 6 8
5 5
1 3 3 4 5
+ 1 4
+ 2 3
- 4 5
- 3 3
- 2 6
5 5
1 1 1 1 1
+ 2 3
- 4 5
+ 1 6
- 2 5
+ 1 8
1 1
1
- 1 1
1 1
1000000000
+ 1000000000 1000000000
4 4 4 5 5
5 5 4 4 3
1 1 2 1 2
0
1000000001

在线编程 IDE

建议全屏模式获得最佳体验