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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[1000005];
  4. int main()
  5. {
  6. int t;;
  7. cin>>t;
  8. while(t--){
  9. int f=1;
  10. int n;
  11. cin>>n;
  12. for(int i=0;i<n;i++){
  13. cin>>a[i];
  14. }
  15. int pos=-1;
  16. for(int i=0;i<n;i++){
  17. if(i!=0&&i!=n-1){
  18. if(a[i-1]<a[i] && a[i]>a[i+1]){
  19. pos=i;
  20. }
  21. }
  22. }
  23. //cout<<pos<<" "<<a[pos]<<endl;
  24. for(int i=0;i<n;i++){
  25. if(i<pos){
  26. if(a[i]>=a[i+1]) f=0;
  27. }
  28. if(i>pos){
  29. if(a[i]>=a[i-1]) f=0;
  30. }
  31. }
  32. f?puts("Yes"):puts("No");
  33. }
  34. }

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. day06_04 购物车讲解02

    1.0 补充知识 a,b = [2,3] print(a) print(b) #>>>2 #>>>3 a,b = (2,3) print(a) print(b) # ...

  2. 利用jsoup抓取网页图片

    jsoup简介 jsoup is a Java library for working with real-world HTML. It provides a very convenient API ...

  3. codeblocks17.12 debug 报错:ERROR: You need to specify a debugger program in the debuggers's settings.

    DebugERROR: You need to specify a debugger program in the debuggers's settings.(For MinGW compilers, ...

  4. 容器基础(一): Docker介绍

    IaaS IaaS阶段, 用户租借基础设施,但是还是需要像以前管理服务器那样,用脚本或者手工方式在这些机器上部署应用.这个过程中当然难免会碰到云端机器和本地机器环境不一致的问题.想想每一次同步不同机器 ...

  5. JSP/Servlet Web 学习笔记 DayThree

    JSP内置对象 使用JSP语法可以存取这些内置对象来执行JSP网页的Servlet环境相互作用.内置对象其实是由特定的Java类所产生的.每一种内置对象都映射到一个特定的Java类或者端口,在服务器运 ...

  6. 如何使能diskquota

    quotacheck -avug quotaon -avug setquota -u test1 10000 20000 /mountpoint quota -uv test1

  7. JZOJ 5305 C先生

    题意: 有一个n个点,m条边的图,没有重边.自环,且每一条边最多属于一个环路. 给出q组询问,每次询问u,v两点间的路径有多少种可能. 思路: 先看下方样例说明: 由样例说明可以得知,路径上每经过一个 ...

  8. [poj] 3180 the cow prom

    原题 这是一道强连通分量板子题. 我们只用输出点数大于1的强连通分量的个数! #include<cstdio> #include<algorithm> #include< ...

  9. 3.Docker与LXC、虚拟化技术的区别——虚拟化技术本质上是在模拟硬件,Docker底层是LXC,本质都是cgroups是在直接操作硬件

    先说和虚拟化技术的区别 难道虚拟技术就做不到吗? 不不不,虚拟技术也可以做到,但是会有一定程度的性能损失,灵活度也会下降.容器技术不是模仿硬件层次,而是 在Linux内核里使用cgroup和names ...

  10. codeforces gym/100814 humming distance (二进制位数比较)

    Gym - 100814I I. Salem time limit per test 1 second memory limit per test 1024 megabytes input stand ...