#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const int N=100086;
int a[N],up[N],down[N],up_same[N],down_same[N],n;
void getdp(int dp[],int num[])
{
vector<int> v;
dp[n-1]=1;
v.push_back(a[n-1]);
for(int i=n-2;i>=0;i--)
{
int len=v.size();
if(a[i]>v[len-1])
{
dp[i]=len+1;
v.push_back(a[i]);
num[i]=1;
}
else if(a[i]==v[len-1])
{
int low=lower_bound(v.begin(),v.end(),a[i])-v.begin();
int upp=upper_bound(v.begin(),v.end(),a[i])-v.begin();
dp[i]=len+1;
v.push_back(a[i]);
num[i]=upp-low;
}
else
{
int low=lower_bound(v.begin(),v.end(),a[i])-v.begin();
int upp=upper_bound(v.begin(),v.end(),a[i])-v.begin();
dp[i]=upp+1;
v[upp]=a[i];
num[i]=upp-low;
}
}
}
int main()
{
int T,res;
cin>>T;
while(T--)
{
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
getdp(up,up_same);
for(int i=0;i<n;i++)a[i]=0-a[i];
getdp(down,down_same);
res=0;
for(int i=0;i<n;i++)res=max(up[i]+down[i]-min(up_same[i],down_same[i]),res);
cout<<res-1<<endl;
}
return 0;
}
hdu4604
最新推荐文章于 2019-10-01 10:52:24 发布