代码
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
const int maxn = 100010;
vector<int> sequence;
int maxL, minR, cnt, k, n, tmp;
bool bigger[maxn];
bool pivot[maxn];
int main()
{
cin >> k;
while (k--)
{
scanf("%d", &n);
sequence.clear();
for (int i = 0; i < n; i++)
{
scanf("%d", &tmp);
sequence.emplace_back(tmp);
}
fill(bigger, bigger + n, false);
fill(pivot, pivot + n, false);
maxL = -1, minR = 0x3fffffff;
cnt = 0;
for (int i = 0; i < n; i++)
{
if (sequence[i] > maxL)
{
bigger[i] = true;
maxL = sequence[i];
}
}
for (int i = n - 1; i >= 0; i--)
{
if (bigger[i] && sequence[i] < minR)
{
cnt++;
pivot[i] = true;
if (cnt == 3) break;
}
if (sequence[i] < minR)minR = sequence[i];
}
if (cnt >= 3) cout << "Yes" << endl;
else if (cnt == 2 && (pivot[0] || pivot[n - 1]))cout << "Yes" << endl;
else cout << "No" << endl;
}
}
标签:cnt,Run,sequence,int,Quicksort,Second,maxL,minR,bigger
From: https://www.cnblogs.com/index-12/p/17341224.html