Codeforces Round 975 (Div. 1)
B
Speedbreaker
Codeforces
1900
原题
← AC →
翻译中…
翻译中…

There are $n$ cities in a row, numbered $1, 2, \ldots, n$ left to right.

翻译中…
  • At time $1$, you conquer exactly one city, called the starting city.
  • At time $2, 3, \ldots, n$, you can choose a city adjacent to the ones conquered so far and conquer it.
翻译中…

You win if, for each $i$, you conquer city $i$ at a time no later than $a_i$. A winning strategy may or may not exist, also depending on the starting city. How many starting cities allow you to win?

翻译中…

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 2 \cdot 10^5$) — the number of cities.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the deadlines for conquering the cities.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output a single integer: the number of starting cities that allow you to win.

翻译中…

Note

翻译中…

In the first test case, cities $2$, $3$, and $4$ are good starting cities.

翻译中…

In the second test case, there are no good starting cities.

翻译中…

In the third test case, the only good starting city is city $5$.

翻译中…

样例

Input #1
3
6
6 3 3 3 5 5
6
5 6 4 1 4 5
9
8 6 4 2 1 3 5 7 9
Output #1
3
0
1
InputCopy OutputCopy
题目信息
题号
2018B
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
动态规划
贪心
模拟
双指针

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