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. 微信小程序之界面交互反馈

    交互反馈就是在用户出发某事件之后,给用户一个反馈信息,这要是一个很友好的习惯. 在小程序中是通过一下几种方式实现的: 1.wx.showToast()方法 showToast: function (p ...

  2. 写一个TODO App学习Flutter本地存储工具Moor

    写一个TODO App学习Flutter本地存储工具Moor Flutter的数据库存储, 官方文档: https://flutter.dev/docs/cookbook/persistence/sq ...

  3. 这些基本的 HTML5 标签你不能不知道

    HTML5元素 HTML5是HTML最新的修订版本,2014年10月由万维网联盟(W3C)完成标准制定. HTML5是用来写网页的一门标记语言. 使用的时候需要在首行声明HTML,如:<!DOC ...

  4. JAVA自动化之Junit单元测试框架详解

    一.JUnit概述&配置 1.Junit是什么? Junit是一个Java 编程语言的开源测试框架,用于编写和运行测试.官网 地址:https://junit.org/junit4/ 2.Ma ...

  5. python学习 0 python简介

    一.Python简介 python是一门简单易学又功能强大的编程语言.它具有高效的高级数据结构和简单而有效的面向对象编程的特性.python优雅的语法和动态类型.以及其解释性的性质,使它在许多领域和大 ...

  6. Java第三十三天,IO操作(续集),字符转换流

    计算机都是以二进制码格式存储文件的,但是在读写文件的过程中,每个应用程序都有自己的编码格式.FileWrite和FileRead类是通过查询系统默认码表进行读写的,因此在自己的系统上能够实现编码的智能 ...

  7. Linux服务器架设篇,DNS服务器(三),正反解区域的配置

    一.大体架构 DNS服务器其实只有一个"真正"的配置文件,即 /etc/named.conf .其他的配置文件都是依据此配置展开的.每个域都需要两个配置文件,即正解文件和反解文件. ...

  8. PTA 6-1 单链表逆转

    本题是一个非常经典的题目:单链表逆转. 这是链表结点的定义: typedef struct Node *PtrToNode; struct Node { ElementType Data; /* 存储 ...

  9. Angular input / ion-input ion-searchbar 实现软件盘换行 改 搜索 并且触发搜索方法 Android iOS适用

    Angular 实现软件盘 换行 改 搜索 并且除非 搜索方法:    Form 必须有 action="javascript: return true;”   input / ion-in ...

  10. 《JavaScript 模式》读书笔记(6)— 代码复用模式2

    上一篇讲了最简单的代码复用模式,也是最基础的,我们普遍知道的继承模式,但是这种继承模式却有不少缺点,我们下面再看看其它可以实现继承的模式. 四.类式继承模式#2——借用构造函数 本模式解决了从子构造函 ...