A sequence of \(n\) integers \(a_1, a_2, \dots, a_n\) is called a peak, if and only if there exists exactly one integer \(k\) such that \(1 < k < n\), and \(a_i < a_{i+1}\) for all \(1 \le i < k\), and \(a_{i-1} > a_i\) for all \(k < i \le n\).

Given an integer sequence, please tell us if it's a peak or not.

Input

There are multiple test cases. The first line of the input contains an integer \(T\), indicating the number of test cases. For each test case:

The first line contains an integer \(n\) (\(3 \le n \le 10^5\)), indicating the length of the sequence.

The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (\(1 \le a_i \le 2 \times 10^9\)), indicating the integer sequence.

It's guaranteed that the sum of \(n\) in all test cases won't exceed \(10^6\).

Output

For each test case output one line. If the given integer sequence is a peak, output "Yes" (without quotes), otherwise output "No" (without quotes).

Sample Input

7

5

1 5 7 3 2

5

1 2 1 2 1

4

1 2 3 4

4

4 3 2 1

3

1 2 1

3

2 1 2

5

1 2 3 1 2

Sample Output

Yes

No

No

No

Yes

No

No

#include<bits/stdc++.h>

using namespace std;
int a[1000005];
int main()
{
int t;;
cin>>t;
while(t--){
int f=1;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
int pos=-1;
for(int i=0;i<n;i++){
if(i!=0&&i!=n-1){
if(a[i-1]<a[i] && a[i]>a[i+1]){
pos=i;
}
}
}
//cout<<pos<<" "<<a[pos]<<endl;
for(int i=0;i<n;i++){
if(i<pos){
if(a[i]>=a[i+1]) f=0;
}
if(i>pos){
if(a[i]>=a[i-1]) f=0;
}
}
f?puts("Yes"):puts("No");
}
}

Peak的更多相关文章

  1. [LeetCode] Find Peak Element 求数组的局部峰值

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  2. LeetCode 162 Find Peak Element

    Problem: A peak element is an element that is greater than its neighbors. Given an input array where ...

  3. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  4. [LintCode] Find Peak Element 求数组的峰值

    There is an integer array which has the following features: The numbers in adjacent positions are di ...

  5. lintcode 75 Find Peak Element

    Hi 大家,这道题是lintcode上的find peak element的题,不是leecode的那道, 这两道题是有区别的,这道题的题目中说明了:只有左右两侧的数都小于某个元素,这种才是峰值, 而 ...

  6. 【leetcode】Find Peak Element

    Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...

  7. ChIP-seq Peak caller MACS index out of range问题解决

    使用MACS1.4 进行peak calling的时候发现一个比较奇怪的问题: 我的某些文件无法被MACS1.4 进行peak calling,出现如下的信息: Traceback (most rec ...

  8. find the peak value

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  9. Java for LeetCode 162 Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  10. LeetCode Find Peak Element

    原题链接在这里:https://leetcode.com/problems/find-peak-element/ 题目: A peak element is an element that is gr ...

随机推荐

  1. Category的真相

    Objective-C 中的 Category 就是对设计模式中装饰模式的一种具体实现.它的主要作用是在不改变原有类的前提下,动态地给这个类添加一些方法. 使用场景 根据苹果官方文档对 Categor ...

  2. 剑指Offer - 九度1348 - 数组中的逆序对

    剑指Offer - 九度1348 - 数组中的逆序对2014-01-30 23:19 题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个 ...

  3. canda 常用命令

    1.获取版本 conda -V conda --version 2.获取帮助 conda -h conda --help 查看某一命令的帮助 conda install -h conda instal ...

  4. HTML5 FileReader接口学习笔记

    1.FileReader概述 FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据. 其中F ...

  5. Entity Framework(一)

    相关知识点复习: 1.var 类型推断: var p=new Person(); 2.匿名类型: var a=new {Name="wang",Age=12  }; 3.给新创建的 ...

  6. PEAR DB 事务相关

    1.autoCommit().commit().rollback() function autoCommit($onoff=false) 指定是否自动提交事务.有的后端数据库不支持. function ...

  7. Sprint 站立会议(个人)

    昨天做: 开Sprint会议确定并绘制Backlog. 今天做: 系统主窗体格局 编程环境搭建(部分) 遇到问题: 缺乏经验,没有好的总体规划. 团队博客园:http://www.cnblogs.co ...

  8. 201621123033 《Java程序设计》第8周学习总结

    第八次作业 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 首先调 ...

  9. error MSB6006: “aapt.exe”已退出,代码为-1073741819

    今天升级了Xamarin和Android SDK之后连模板程序生成都报这个错误,真是想剁手啊,最后在google同学的帮助下搜索到了Xamarin官方论坛上的回答 这个问题是生成工具版本选择的问题,似 ...

  10. windows系统设备管理器显示全部硬件

    下面的小命令能让隐藏的未卸载掉的硬件设备彻底现身:开始-运行-CMD C:\> C:\>start devmgmt.msc 之后再在Windows 的设备管理器中,单击菜单“显示”-“显示 ...