题目地址:https://codeforces.com/contest/1291/problem/B
题意:
输入n,接着输入n个数字,这n个数字构成一个数组。
你可以对数组中任意一个数字进行任意次数的-1操作。
问:这个数组能不能变成一个锐化的数组。
数组锐化:三种形式
1.递增:{0,1,2,3,4}
2.递减:{4,3,2,1,0}
3.只有一个坡度:{0,1,2,3,4,3,2,1,0}
解决方法:
从头到尾遍历一遍,记录a[0] >= 0,a[1] >= 1......的数量,如果遇到a[i]<i,则退出并记录数量x;
再从尾到头遍历一遍a[n - 1] >= 0, a[n - 2] >= 1....的数量,遇到>的话就退出并记录数量y;
如果x+y>n则可以锐化,否则不可以。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#define ll long long
#define dd double
#define PI acos(-1.0)
#define f(i, x, y) for(ll i = x; i < y; i++)
using namespace std;
const ll MAXN = 2e5 + 5;
ll a[300005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll t; cin >> t;
while (t--) {
ll n; cin >> n;
f(i, 0, n)cin >> a[i];
ll x = 0;
f(i, 0, n) {
if (a[i] >= x) {
x++;
}
else {
break;
}
}
ll y = 0;
for (ll i = n - 1; i >= 0; i--) {
if (a[i] >= y) {
y++;
}
else {
break;
}
}
if (x + y > n) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
}