Description:

A sequence of integers a 1 , a 2 , , a n a_{1},a_{2},……,a_{n} a1,a2,,an is called a peak, if and only if there exists exactly one integer k such that 1 &lt; k &lt; n 1 &lt; k &lt; n 1<k<n , and a i &lt; a i + 1 a_{i} &lt; a_{i+1} ai<ai+1 for all i i &lt; k i \le i &lt; k ii<k , and a i 1 &gt; a i a_{i-1} &gt; a_{i} ai1>ai for all k &lt; i n k &lt; i \le n k<in .

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 n 1 0 5 3 \le n \le 10^{5} 3n105 ), indicating the length of the sequence.

The second line contains n integers a 1 , a 2 , , a n a_{1},a_{2},……,a_{n} a1,a2,,an ( 1 a i 2 × 1 0 9 1 \le a_{i} \le 2 \times 10^{9} 1ai2×109 ), indicating the integer sequence.

It’s guaranteed that the sum of n in all test cases won’t exceed 1 0 6 10^{6} 106 .

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

题目连接

判断数列是否先增后降(不能相等),直接在输入时判断标记即可。

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
const double eps = 1e-5;
const double pi = asin(1.0)*2;
const double e = 2.718281828459;

int t;
int n;
ll a[maxn];
bool flag;
bool ans;

int main() {
    //fropen("in.txt", "r", stdin);
    scanf("%d", &t);
    while (t--) {
        flag = 1;
        ans = 1;
        scanf("%d", &n);
        scanf("%lld", &a[0]);
        for (int i = 1; i < n; ++i) {
            scanf("%lld", &a[i]);
            if (a[i] == a[i - 1]) {
                ans = 0;
            }
            if (!ans) {
                continue;
            }
            if (flag) {
                if (a[i] < a[i - 1]) {
                    if (i == 1) {
                        ans = 0;
                    }
                    flag = 0;
                }
            }
            else {
                if (a[i] > a[i - 1]) {
                    ans = 0;
                }
            }
        }
        if (ans && !flag) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    return 0;
}