CF2210B.Simply Sitting on Chairs

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

Simply Sitting on Chairs

There are nn chairs in a row, initially all unmarked.

You are given a permutation pp^{\text{∗}} of length nn.

Now, you play a game. You visit each chair sequentially, starting from the 11-st chair. At the ii-th chair, you can do the following:

  • If the ii-th chair is already marked, then you end the game immediately without sitting on it.
  • Otherwise, you can choose to sit on the chair or skip it and move to the next chair.
  • If you choose to sit on the chair, then after standing up, you mark the pip_i-th chair and move to the next chair.

If all the nn chairs are visited, the game ends.

Your task is to determine the maximum number of chairs that you can sit on.

^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2\cdot 10^5) — the number of chairs.

The second line of each test case contains nn distinct integers p1,p2,,pnp_1, p_2,\ldots,p_{n} — the permutation pp.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5.

Output

Output a single integer — the maximum number of chairs you can sit on.

Note

In the first test case, you can proceed as follows:

  1. You visit the 11-st chair, sit on it, and mark the 33-rd chair.
  2. You visit the 22-nd chair, sit on it, and mark the 22-nd chair.
  3. You visit the 33-rd chair. Since it is marked, you end the game.

Therefore, using this sequence, you can sit on a total of 22 chairs. It can be shown that the maximum number of chairs using any sequence of moves is 22.

In the second test case, you can proceed as follows:

  1. You visit the 11-st chair, sit on it, and mark the 44-th chair.
  2. You visit the 22-nd chair and skip it.
  3. You visit the 33-rd chair, sit on it, and mark the 22-nd chair.
  4. You visit the 44-th chair. Since it is marked, you end the game.

Therefore, using this sequence, you can sit on a total of 22 chairs. It can be shown that the maximum number of chairs using any sequence of moves is 22.

Samples

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

在线编程 IDE

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