啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊,
之前觉得思路简单,代码复杂看不懂,,现在是代码简单,思路复杂,还是看不懂
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
我怎么这么懒,懒得连注释都懒得写,,这以后可得怎么办啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
然后这题我们用树状数组做
首先找s1数组中的元素在排序后的数组中的位置,也是第几大,
然后查询比他小的最长上升子序列的长度,然后+1,判断最大值
然后再把他更新进去。。。。。。。。。。
#include<iostream>
#include<algorithm>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<cctype>
#include<vector>
#include<limits.h>
#include<queue>
#include<stack>
using namespace std;
const int maxn=1e5+10;
int p[maxn],s1[maxn],s2[maxn],n;
int lowbit(int x)
{
return x&(-x);
}
void change(int x,int y)
{
while(x<=n)
{
p[x]=max(p[x],y);
x+=lowbit(x);
}
}
int getsum(int x)
{
int ans=0;
while(x)
{
ans=max(ans,p[x]);
x-=lowbit(x);
}
return ans;
}
int main()
{
int len,i,ans,sum,a;
scanf("%d",&n);
for(i=0; i<n; ++i)
{
scanf("%d",&s1[i]);
s2[i]=s1[i];
}
sort(s2,s2+n);
len=unique(s2,s2+n)-s2;
for(i=0,ans=0; i<n; ++i)
{
a=lower_bound(s2,s2+len,s1[i])-s2+1;
sum=getsum(a-1)+1;
ans=max(ans,sum);
change(a,sum);
}
cout<<ans<<endl;
return 0;
}