题目链接:https://nanti.jisuanke.com/t/17319
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define lson step<<1
#define rson step<<1|1
#define getMID (l+r)>>1
#define maxn 100005
#define LL long long
using namespace std;
int ans;
int tree[maxn<<2];
void pushup(int step)
{
tree[step]=max(tree[lson],tree[rson]);
}
void update(int l,int r,int pos,int value,int step)
{
if(l==r)
{
tree[step]=max(tree[step],value);
return ;
}
int mid=getMID;
if(pos<=mid)
update(l,mid,pos,value,lson);
else
update(mid+1,r,pos,value,rson);
pushup(step);
}
void query(int l,int r,int left,int right,int step)
{
if(l==left&&r==right)
{
ans=max(ans,tree[step]);
return ;
}
int mid=getMID;
if(right<=mid)
query(l,mid,left,right,lson);
else if(left>mid)
query(mid+1,r,left,right,rson);
else
{
query(l,mid,left,mid,lson);
query(mid+1,r,mid+1,right,rson);
}
}
int main()
{
int a,w;
int res=0;
while(scanf("%d",&a)!=EOF)
{
if(a<0)
continue;
if(a>=10000)
{
a-=10000;
w=5;
}
else
w=1;
ans=0;
query(0,maxn,0,a,1);//先查找,找出比a小的数的区间非递增子序列的权值的最大值
update(0,maxn,a,ans+w,1);//更新操作,如果包含上这个数看看能否更新最优解
res=max(res,ans+w);//不断取最优解
}
printf("%d\n",res);
return 0;
}