就,,学到了O(nlogn)啊啊啊啊啊。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
#define MAXN 10005
int dpl[MAXN],dpd[MAXN];
int N,Stack[MAXN],top;
int src[MAXN];
int fun(int ele,int &cnt)
{
if (cnt==0 || Stack[cnt]<ele ) Stack[++cnt]=ele;
else
{
int pos=lower_bound(Stack,Stack+cnt,ele)-Stack;
Stack[pos]=ele;
}
return cnt;
}
int main()
{
//freopen("sample.txt","r",stdin);
while (scanf("%d",&N)!=EOF)
{
memset(dpl,0,sizeof(dpl));
memset(dpd,0,sizeof(dpd));
memset(Stack,0,sizeof(Stack));
top=0;
for (int i=0;i<N;i++)
{
scanf("%d",&src[i]);
dpl[i]=fun(src[i],top);
}
top=0;
for (int i=N-1;i>=0;i--)
{
dpd[i]=fun(src[i],top);
}
int ans=0;
for (int i=0;i<N;i++)
ans=max(ans,min(dpd[i],dpl[i]));
printf("%d\n",ans*2-1);
}
return 0;
}