link:点击打开链接
树状数组,需要离散化!需要离散化!需要离散化!
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define sqr(a) (a)*(a)
#define For(i,m,n) for(int i=m;i<=n;i++)
#define Dor(i,n,m) for(int i=n;i>=m;i--)
#define lan(a,b) memset(a,b,sizeof(a))
#define maxn 500010
using namespace std;
struct node
{
int x,id;
};
bool cmp(node a,node b)
{
return a.x<b.x;
}
int shu[maxn];
int n;
node a[maxn];
int b[maxn];
int lowbit(int i)
{
return i&(-i);
}
int query(int i)
{
int ans=0;
if(i==0)
return 0;
while(i>0)
{
ans=max(ans,shu[i]);
i-=lowbit(i);
}
return ans;
}
void update(int p,int i)
{
while(i<=1000000)
{
shu[i]=max(p,shu[i]);
i+=lowbit(i);
}
}
int main()
{
// freopen("1.txt","r",stdin);
//freopen("2.txt","w",stdout);
while(~scanf("%d",&n))
{
int maxx=0;
lan(a,0);
lan(b,0);
lan(shu,0);
map<int ,int> vis;
For(i,1,n)
{
int tem;
scanf("%d",&tem);
a[i].x=tem;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
int sum=1;
b[a[1].id]=1;
For(i,2,n)
{
if(a[i].x!=a[i-1].x)
sum++;
b[a[i].id]=sum;
}
// For(i,1,n)
// printf("%d ",b[i]);
// puts("");
For(i,1,n)
{
int t=query(b[i]-1);
// printf("i=%d t=%d\n",i,t);
maxx=max(maxx,t+1);
update(t+1,b[i]);
}
printf("%d\n",maxx);
}
return 0;
}