Codeforces Round #616(Div.2) Array Sharpening

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 1kn1≤k≤n such that a1<a2<<aka1<a2<…<ak and ak>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 (1in1≤i≤n) such that ai>0ai>0 and assign ai:=ai1ai:=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 (1t15 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 (1n31051≤n≤3⋅105).

The second line of each test case contains a sequence of nn non-negative integers a1,,ana1,…,an (0ai1090≤ai≤109).

It is guaranteed that the sum of nn over all test cases does not exceed 31053⋅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.

解题思路:

给你一串数列,可以的操作是每一个数都能变成比它小的非负数,问你能不能将其变成严格的递增递减数列——从小到大再到小

如果可以,那么这个数列一定可以变成类似0123210这种样子,

所以,我们只需要将数列分成两部分,

前一部分的数,只需要大于其位置-1的数即可

后一部分的数,只需要大于n-其位置的数即可

特别比对一下偶数时中间两个数即可

代码如下:

 1 #include<bits/stdc++.h>
 2 #define mem(a) memset(a,0,sizeof(a))
 3 #define forn(i,n) for(int i=0;i<n;++i)
 4 #define for1(i,n) for(int i=1;i<=n;++i)
 5 #define IO std::ios::sync_with_stdio(false); std::cin.tie(0)
 6 using namespace std;
 7 typedef long long ll;
 8 const int maxn=1e6+5;
 9 const int inf=0x3f3f3f3f;
10 
11 int n,m,s,t,k;
12 int num[maxn];
13 char c;
14 
15 int main()
16 {
17     IO;
18     cin>>t;
19     while(t--)
20     {
21         bool flag=true;
22         cin>>n;
23         for1(i,n)
24         {
25             cin>>num[i];
26         }
27        int l=1,r=n;
28        while(l!=r)
29        {
30            if(l+1==r)
31            {
32                if(num[l]<l-1||num[r]<n-r)
33                 flag=false;
34                if(num[l]==num[r]&&num[l]==l-1)
35                 flag=false;
36                break;
37            }
38            if(num[l]<l-1||num[r]<n-r)
39            {flag=false;break;}
40            l++;
41            r--;
42        }
43         if(l==r)
44             if(num[l]<l-1)
45                 flag=false;
46         if(flag)
47             cout<<"Yes"<<endl;
48         else
49             cout<<"No"<<endl;
50     }
51     return 0;
52 }

 

posted @ 2020-02-03 15:36  小松QAQ  阅读(168)  评论(0编辑  收藏  举报