http://acm.hdu.edu.cn/showproblem.php?pid=5532
题意大致是一组数中去掉一个数后问剩下的数是否构成非严格单调序列
正反各跑一遍最长非严格连续子序列,存在长度大于等于n-1的就满足YES,注意这里的YES NO都是大写
1 #include<cstdio> 2 using namespace std; 3 int a[100010],c[100010]; 4 int main() 5 { 6 int t,i,j,n; 7 scanf("%d",&t); 8 while (t--) 9 { 10 scanf("%d",&n); 11 for (i=1;i<=n;i++) 12 scanf("%d",&a[i]); 13 int ans=1; 14 c[ans]=a[1]; 15 for (i=2;i<=n;i++) 16 { 17 if (a[i]>=c[ans]) c[++ans]=a[i]; 18 else if (a[i]<c[1]) c[1]=a[i]; 19 else{ 20 int left=1,right=ans,mid; 21 while (left<right-1) 22 { 23 mid=(left+right)/2; 24 if (a[i]>=c[mid]) left=mid; 25 else right=mid; 26 } 27 if (a[i]<=c[right]) c[right]=a[i]; 28 } 29 } 30 if (ans>=n-1){ 31 printf("YES\n");continue; 32 } 33 ans=1; 34 c[ans]=a[n]; 35 for (i=n-1;i>=1;i--) 36 { 37 if (a[i]>=c[ans]) c[++ans]=a[i]; 38 else if (a[i]<c[1]) c[1]=a[i]; 39 else{ 40 int left=1,right=ans,mid; 41 while (left<right-1) 42 { 43 mid=(left+right)/2; 44 if (a[i]>=c[mid]) left=mid; 45 else right=mid; 46 } 47 if (a[i]<=c[right]) c[right]=a[i]; 48 } 49 } 50 if (ans>=n-1) printf("YES\n"); 51 else printf("NO\n"); 52 } 53 return 0; 54 }