optimum cpp code for : Speedbreaker time limit per test2 seconds memory limit per…
- User
optimum cpp code for : Speedbreaker time limit per test2 seconds memory limit per test256 megabytes Djjaner - Speedbreaker ⠀ There are n cities in a row, numbered 1,2,…,n left to right.
At time 1 , you conquer exactly one city, called the starting city. At time 2,3,…,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 ai . 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≤t≤104 ). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤2⋅105 ) — the number of cities.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n ) — the deadlines for conquering the cities.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
Output For each test case, output a single integer: the number of starting cities that allow you to win.
Example InputCopy 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 OutputCopy 3 0 1 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 .
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.