Array Sharpening CodeForces - 1291B(思维)
You’re given an array a1,…,ana1,…,an of nn non-negative integers.
Let’s call it sharpened if and only if there exists an integer 1≤k≤n1≤k≤n such that a1<a2<…<aka1<a2<…ak+1>…>anak>ak+1>…>an. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
The arrays [4][4], [0,1][0,1], [12,10,8][12,10,8] and [3,11,15,9,7,4][3,11,15,9,7,4] are sharpened;
The arrays [2,8,2,8,6,5][2,8,2,8,6,5], [0,1,1,0][0,1,1,0] and [2,5,6,9,8,8][2,5,6,9,8,8] are not sharpened.
You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any ii (1≤i≤n1≤i≤n) such that ai>0ai>0 and assign ai:=ai?1ai:=ai?1.
Tell if it’s possible to make the given array sharpened using some number (possibly zero) of these operations.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤15 0001≤t≤15 000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer nn (1≤n≤3?1051≤n≤3?105).
The second line of each test case contains a sequence of nn non-negative integers a1,…,ana1,…,an (0≤ai≤1090≤ai≤109).
It is guaranteed that the sum of nn over all test cases does not exceed 3?1053?105.
Output
For each test case, output a single line containing “Yes” (without quotes) if it’s possible to make the given array sharpened using the described operations, or “No” (without quotes) otherwise.
Example
Input
10
1
248618
3
12 10 8
6
100 11 15 9 7 8
4
0 1 1 0
2
0 0
2
0 1
2
1 0
2
1 1
3
0 1 0
3
1 0 1
Output
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
No
Note
In the first and the second test case of the first test, the given array is already sharpened.
In the third test case of the first test, we can transform the array into [3,11,15,9,7,4][3,11,15,9,7,4] (decrease the first element 9797 times and decrease the last element 44 times). It is sharpened because 3<11<153<11<15 and 15>9>7>415>9>7>4.
In the fourth test case of the first test, it’s impossible to make the given array sharpened.
太菜了,B題都想了那么久。。
思路:這個題目的難點是沒有辦法處理那個拐點,如果按照原來的數組來的話,可能會出現很多拐點。但是我們仔細想一下,我們最后可以把數組處理成0 1 2 3…3 2 1 0的樣子,這應該是處理的極致了。那么我們就遍歷數組,如果a[i]>=i的話就將它處理成i,到a[i]<i的那一點這就是拐點了,那么我們就看這一點以及后面的數字,不斷遍歷,并將a[i]更新為min(a[i-1]-1,a[i]),如果出現的負數就不行了。
但是還有一種情況,就是遞減序列,即拐點出現在第一位,根據以上做法是不可行的。我們轉換一下,變成遞增序列就可以了。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Array Sharpening CodeForces - 1291B(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mind Control CodeFor
- 下一篇: Erasing Zeroes CodeF