Codeforces Round 1010 (Div. 2, Unrated)
D
Balancing
Codeforces
未评级
原题
← CE →
翻译中…

Ecrade has an integer array $a_1, a_2, \ldots, a_n$. It's guaranteed that for each $1 \le i \lt n$, $a_i \neq a_{i+1}$.

翻译中…

Ecrade can perform several operations on the array to make it strictly increasing.

翻译中…

In each operation, he can choose two integers $l$ and $r$ ($1 \le l \le r \le n$) and replace $a_l, a_{l+1}, \ldots, a_r$ with any $r-l+1$ integers $a'_l, a'_{l+1}, \ldots, a'_r$ satisfying the following constraint:

翻译中…
  • For each $l \le i \lt r$, the comparison between $a'_i$ and $a'_{i+1}$ is the same as that between $a_i$ and $a_{i+1}$, i.e., if $a_i \lt a_{i + 1}$, then $a'_i \lt a'_{i + 1}$; otherwise, if $a_i \gt a_{i + 1}$, then $a'_i \gt a'_{i + 1}$; otherwise, if $a_i = a_{i + 1}$, then $a'_i = a'_{i + 1}$.
翻译中…

Ecrade wants to know the minimum number of operations to make the array strictly increasing. However, it seems a little difficult, so please help him!

翻译中…

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$ ($2 \le n \le 2 \cdot 10^5$).

翻译中…

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

翻译中…

It is guaranteed that for each $1 \le i \lt n$, $a_i \neq a_{i+1}$.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer representing the minimum number of operations to make the array strictly increasing.

翻译中…

Note

翻译中…

In the first test case, a possible way to obtain the minimum number of operations:

翻译中…
  • In the first operation, choose $l = 2, r = 2$ and $a'_2 = 4$, then $a=[3, 4, 1]$;
  • In the second operation, choose $l = 1, r = 2$ and $a'_1 = -1, a'_2 = 0$, then $a=[-1, 0, 1]$.
翻译中…

In the second test case, a possible way to obtain the minimum number of operations:

翻译中…
  • In the first operation, choose $l = 2, r = 3$ and $a'_2 = 4, a'_3 = 5$, then $a = [3, 4, 5]$.
翻译中…

In the third test case, a possible way to obtain the minimum number of operations:

翻译中…
  • In the first operation, choose $l = 2, r = 3$ and $a'_2 = -1, a'_3 = 1$, then $a = [-2, -1, 1, 2]$.
翻译中…

样例

Input #1
4
3
3 2 1
3
3 1 2
4
-2 -5 5 2
7
1 9 1 9 8 1 0
Output #1
2
1
1
3
InputCopy OutputCopy
题目信息
题号
2082D
时间限制
2 s
内存限制
512 MB

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