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]),如果出现的负数就不行了。
但是还有一种情况,就是递减序列,即拐点出现在第一位,根据以上做法是不可行的。我们转换一下,变成递增序列就可以了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=3e5+100;
int a[maxx];
int b[maxx];
int n;inline int fcs(int c[])
{int pos=-1;for(int i=0;i<n;i++){if(c[i]>=i) c[i]=i;else{pos=i;break;}}if(pos==-1) return true;for(int i=pos;i<n;i++){c[i]=min(c[i-1]-1,c[i]);if(c[i]<0) return false;}return true;
}
int main()
{int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++) cin>>a[i];for(int i=0;i<n;i++) b[i]=a[n-i-1];if(fcs(a)||fcs(b)) cout<<"YES"<<endl;else cout<<"NO"<<endl;}return 0;
}
//0 1 4 3 5 4 3 2 1 0

努力加油a啊,(o)/~

Array Sharpening CodeForces - 1291B(思维)相关推荐

  1. Codeforces Round #616 (Div. 2)B. Array Sharpening

    B. Array Sharpening 题目链接-Array Sharpening 题目大意 给你一个序列a[],要求你找出k(1<k<n)使得k位置之前数字是严格单调递增,k之后是严格单 ...

  2. Interesting Array CodeForces - 483D(思维+线段树)

    We'll call an array of n non-negative integers a[1], a[2], -, a[n] interesting, if it meets m constr ...

  3. CodeForces 798D 思维,贪心

    CodeForces 798D 题意:长度为 n的两个数组 a[]和 b[],要找出 k ( k<=n/2+1 )个下标,使得在两个数组中这 k个数的和乘上 2 要大于所有数的和. tags: ...

  4. Array Splitting CodeForces - 1197C

    You are given a sorted array a_1, a_2, \dots, a_na1​,a2​,-,an​ (for each index i > 1i>1 condit ...

  5. B. Bogosort codeforces(思维)

    outputstandard output You are given an array a1,a2,-,an. Array is good if for each pair of indexes i ...

  6. Count Subrectangles CodeForces - 1323B(思维)

    You are given an array a of length n and array b of length m both consisting of only integers 0 and ...

  7. F. Strange Array(Codeforces Round #727 (Div. 2))(主席树)

    F. Strange Array 给定一个长度为nnn的数组aaa,1≤ai≤n1 \leq a_i \leq n1≤ai​≤n,对于每个aia_iai​,我们要找到一个l≤i,r≥il \leq i ...

  8. 2020牛客暑期多校训练营(第一场)A B-Suffix Array(后缀数组,思维)

    链接:https://ac.nowcoder.com/acm/contest/5666/A 来源:牛客网 题目描述 The BBB-function B(t1t2-tk)=b1b2-bkB(t_1 t ...

  9. codeforces - 1315C - 思维题

    原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...

最新文章

  1. 面试----Object类
  2. python按时间排序 文件
  3. 部署Ceph集群(块存储,文件系统存储,对象存储)
  4. VTK:Math之MatrixTranspose
  5. Java 动态代理实现
  6. gb50243-2016通风与空调工程施工质量验收规范_07K304 空调机房设计与安装
  7. 如何进行时间序列的特征工程?
  8. 利用计算机发布调度命令时必须严格遵守,调度命令规范格式(22页)-原创力文档...
  9. 清明上河图动图html,《清明上河图》“动”起来是啥样?快来海珠这里观赏!...
  10. 代码实现 outerHTML
  11. oracle10g 杨忠民,开题报告 基于J2EE的DRP系统设计
  12. java孢子进化_孢子的进化起源
  13. amd raid linux驱动,AMD 磁盘阵列控制器 驱动程序下载——更新 AMD 软件
  14. 地理信息系统GIS--介绍
  15. android模拟器命令大全,玩转安卓模拟器命令行
  16. 爬虫学习实践(1)——我的第一个小爬虫
  17. 自然语言处理之词性标注
  18. html带复选框的表格,Html 表格行 ID 复选框
  19. [Debug]modelsim simulation error,vsim:3053
  20. pytorch 利用tensorboard显示loss,acc曲线等

热门文章

  1. 15-description-Objective-C笔记
  2. python比较两个数的和_Python中的is和==比较两个对象的两种方法
  3. 鱼骨图分析法实际案例_让你头脑更精明的十种思考法:鱼骨图
  4. android 8.0应用内安装包,Android 8.0 下载安装进入【安装未知应用】页面,两步简化一步...
  5. 星露谷物语json_星露谷物语 NPC地图显示MOD 怎么让地图显示NPC
  6. java 金字塔样式输出_Java打印金字塔(正实心、正空心,倒实心、倒空心),菱形...
  7. java几种多线程_Java多线程实现的几种方式
  8. python中random中uniform怎么用_Python中的random.uniform()函数教程与实例解析
  9. 摔跤视频软件测试,Apple Watch 4摔倒检测立功:成功救人一命,网友:马上入手!...
  10. Android开发之通过反射获取全局的application