Codeforces Round 1082 (Div. 1)
A1
Lost Civilization (Easy Version)
Codeforces
1300
原题
←A2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, you must compute a value for one sequence. You can hack only if you solved all versions of this problem.

翻译中…

Let's define an algorithm to generate a sequence of $m+k$ integers as follows:

翻译中…
  1. First, receive a sequence $x$ of $m$ integers as input. If $k=0$, terminate immediately and return the sequence $x$.
  2. Then, select any index $1 \le i \le |x|$ and insert $(x_i+1)$ immediately after the element $x_i$.
  3. If $x$ contains exactly $m+k$ integers, terminate and return the sequence $x$. Otherwise, return to the second step.
翻译中…

Alice knows that this algorithm was used by an ancient civilization in order to hide their secrets safely. Alice wants to learn the knowledge that they wanted to hide, but it is not an easy job to infer the input from the output of the algorithm.

翻译中…

Given a sequence $a$ of $n$ integers, determine the length of the shortest sequence that could be given as an input for the algorithm to generate $a$.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 300\,000$).

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^9$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $300\,000$.

翻译中…

Output

翻译中…

For each test case, output the length of the shortest sequence on a separate line.

翻译中…

Note

翻译中…

In the first test case, the sequence $[1]$ can generate the sequence $a=[1,2,3,4,5]$ by the following process:

翻译中…

$$[1] \to [1,\color{red}{2}] \to [1,2,\color{red}{3}] \to [1,2,3,\color{red}{4}] \to [1,2,3,4,\color{red}{5}]$$

翻译中…

In the second test case, the only sequence that can generate $a=[1,3,5,7,9]$ is $a$ itself.

翻译中…

样例

Input #1
5
5
1 2 3 4 5
5
1 3 5 7 9
5
1 2 5 6 5
7
1 2 4 5 3 7 8
9
9 8 9 2 3 4 4 5 3
Output #1
1
5
3
4
3
InputCopy OutputCopy
题目信息
题号
2201A1
时间限制
2 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。