B. Array Sharpening

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

You’re given an array a1,…,an of n non-negative integers.

Let’s call it sharpened if and only if there exists an integer 1≤k≤n such that a1<a2<…ak+1>…>an. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:

The arrays [4], [0,1], [12,10,8] and [3,11,15,9,7,4] are sharpened;

The arrays [2,8,2,8,6,5], [0,1,1,0] and [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 i (1≤i≤n) such that ai>0 and assign ai:=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 t (1≤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 n (1≤n≤3⋅105).

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

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

inputCopy

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

outputCopy

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] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3<11<15 and 15>9>7>4.

In the fourth test case of the first test, it’s impossible to make the given array sharpened.

这个题考虑不能构成的情况,就是从这数左边不能构成,右边也不能构成。然后左右都可以的时候,中间两个可能相等不能构成左右。

#include <bits/stdc++.h>
using namespace std;
int a[300010];
int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin>>n;
bool bk = true;
for (int i = 1; i <= n; i++)
cin>>a[i] ;
for (int i = 1; i <= n; i++)
if (a[i] < min(i - 1, n - i))
{
bk = false;
break;
}
if (n % 2 == 0 && max(a[n / 2], a[n / 2 + 1]) < n / 2)
{
bk = false;
}
if (bk == false)
puts("No");
else
puts("Yes");
}
return 0;
}

Codeforces 1291 Round #616 (Div. 2) B的更多相关文章

  1. Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)

    C. Mind Control You and your n−1 friends have found an array of integers a1,a2,-,an. You have decide ...

  2. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  3. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  4. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  5. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  8. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  9. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

随机推荐

  1. NumPy学习1:基本概念

    NumPy的数组类被称作 ndarray .通常被称作数组.注意numpy.array和标准Python库类array.array并不相同,后者只处理一维数组和提供少量功能.更多重要ndarray对象 ...

  2. zookeeper的下载安装和选举机制(zookeeper一)

    1. 简要概述 Zookeeper是一个开源的分布式的,为分布式应用提供协调服务的框架.Zookeeper从设计模式角度来理解:是一个基于观察者模式设计的分布式服务管理框架它负责存储和管理大家都关心的 ...

  3. java实现图片的上传和展示

    一.注意事项: 1,该项目主要采用的是springboot+thymeleaf框架 2,代码展示的为ajax完成图片上传(如果不用ajax只需要改变相应的form表单配置即可) 二.效果实现: 1,页 ...

  4. 【翻译】创建String 使用“”还是构造函数(new String)

    在java中创建String,通常有以下两种方法. String x = "abc"; String y = new String("abc"); 它们之间有什 ...

  5. GeoGebra重复手段实现

    1.自定义工具部分可以在网上搜一些别人做的工具,主要是把自己经常做的一些任务做成工具,减少重复过程 2.列表部分的简单操作如图所示,实现对三个点的多项式拟合 3.通过序列指令格式可以做一个好玩的效果, ...

  6. linq 高集成化数据访问技术

    一:  新建名为linq的项目 创建 linq 1 在项目里添加文件夹 App_Code; 2 在文件夹(App_Code) 添加  名为db的    Linq To Sql 类  :一个Linq T ...

  7. MySQL服务端恶意读取客户端文件漏洞 (DDCTF2019和国赛均涉及到这个漏洞)

    mysql协议中流程和go语言实现的恶意mysql服务器:https://blog.csdn.net/ls1120704214/article/details/88174003 poc :https: ...

  8. idea中哪些好用到飞起的插件,偷懒神器

    idea中开发人员的偷懒神器-插件  本期推荐一些开发人员常用的一些idea插件.偷懒神器在此,不再秃头! 1. idea安装插件的方法.  file->setting->plugins ...

  9. redis:key命令(二)

    设置一个key:set name hello 获取一个key的值:get name 查看所有的key:keys * 查看key是否存在:exists name 移动key到指定库:move name ...

  10. ES6系列-什么是ES6?新手应该怎么理解

    ECMAScript 是什么 很多初学者都很困惑,ECMAScript是什么?它跟JavaScript有什么关系? 大家注意到了吗?从题目中我们就可以看出来了,ECMAScript是JavaScrip ...