题意:就是求最长上升子序(用nlogn)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e7;
int a[maxm],dp[maxm],n,b[maxm];
int EF(int len,int k)
{
int left=1,right=len;
while(left<=right)
{
int mid=(left+right)>>1;
if(k>dp[mid])
{
left=mid+1;
}
else
{
right=mid-1;
}
}
return left;
}
void LIS()
{
int i,j,ans=1;
dp[1]=a[1];
for(i=2;i<=n;i++)
{
if(a[i]<=dp[1])
{
j=1;
}
else if(a[i]>dp[ans])
{
j=++ans;
}
else
{
j=EF(ans,a[i]);
}
dp[j]=a[i];
b[i]=j;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=1;
}
LIS();
int MIN=-1;
for(i=1;i<=n;i++)
{
MIN=max(MIN,b[i]);
}
printf("%d\n",MIN);
}
return 0;
}