http://acm.hdu.edu.cn/showproblem.php?pid=5532
题意大致是一组数中去掉一个数后问剩下的数是否构成非严格单调序列
正反各跑一遍最长非严格连续子序列,存在长度大于等于n-1的就满足YES,注意这里的YES NO都是大写
#include<cstdio>
using namespace std;
int a[],c[];
int main()
{
int t,i,j,n;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (i=;i<=n;i++)
scanf("%d",&a[i]);
int ans=;
c[ans]=a[];
for (i=;i<=n;i++)
{
if (a[i]>=c[ans]) c[++ans]=a[i];
else if (a[i]<c[]) c[]=a[i];
else{
int left=,right=ans,mid;
while (left<right-)
{
mid=(left+right)/;
if (a[i]>=c[mid]) left=mid;
else right=mid;
}
if (a[i]<=c[right]) c[right]=a[i];
}
}
if (ans>=n-){
printf("YES\n");continue;
}
ans=;
c[ans]=a[n];
for (i=n-;i>=;i--)
{
if (a[i]>=c[ans]) c[++ans]=a[i];
else if (a[i]<c[]) c[]=a[i];
else{
int left=,right=ans,mid;
while (left<right-)
{
mid=(left+right)/;
if (a[i]>=c[mid]) left=mid;
else right=mid;
}
if (a[i]<=c[right]) c[right]=a[i];
}
}
if (ans>=n-) printf("YES\n");
else printf("NO\n");
}
return ;
}