#include #include #include #include #include #include #include #include #include #include #include #define N 100005 #define pop_back pp #define push_back pb #define veci vector #define pii pair typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; using namespace std; int T,n,a[N],b[N],dp[N]; struct node{ int L,R,mx; }tree[N<<2]; void build(int L,int R,int p){ tree[p].L=L,tree[p].R=R,tree[p].mx=0; if(L==R)return; int mid=(L+R)>>1; build(L,mid,p<<1); build(mid+1,R,(p<<1)+1); } void update(int x,int a,int p){ if(tree[p].L==tree[p].R){ tree[p].mx=max(tree[p].mx,a); return; } int mid=(tree[p].L+tree[p].R)>>1; if(x<=mid)update(x,a,p<<1); else update(x,a,(p<<1)+1); tree[p].mx=max(tree[p<<1].mx,tree[(p<<1)+1].mx); } int query(int L,int R,int p){ if(tree[p].L==L&&tree[p].R==R){ return tree[p].mx; } int mid=(tree[p].L+tree[p].R)>>1; if(R<=mid)return query(L,R,p<<1); else if(L>mid)return query(L,R,(p<<1)+1); else return max(query(L,mid,p<<1),query(mid+1,R,(p<<1)|1)); } void Rd(int &res){ res=0;char c; while(c=getchar(),!isdigit(c)); do res=res*10+(c&15); while(c=getchar(),isdigit(c)); } void Input(){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(dp,0,sizeof(dp)); Rd(n); for(int i=1;i<=n;i++){ Rd(a[i]); b[i]=a[i]; } } void Solve(){ sort(b+1,b+1+n); int len=unique(b+1,b+1+n)-b-1; for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+1+len,a[i])-b; build(1,len,1); dp[1]=1; update(a[1],dp[1],1); for(int i=2;i<=n;i++){ if(a[i]!=1)dp[i]=query(1,a[i]-1,1); dp[i]++; update(a[i],dp[i],1); } for(int i=1;i