如果数组元素较大,需要离散化。
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll tree[maxn];
int n;
ll a[maxn];
ll lowbit(ll x)
{
return x&(-x);
}
ll query(ll x)
{
ll res=0ll;
while(x)
{
res=max(res,tree[x]);
x-=lowbit(x);
}
return res;
}
void modify(ll id,ll x)
{
while(id<maxn)
{
tree[id]=max(tree[id],x);
id+=lowbit(id);
}
}
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\code_stream\\out.txt","w",stdout);
gbtb;
cin>>n;
ll ans=0ll;
ll x;
repd(i,1,n)
{
cin>>a[i];
x=query(a[i])+1;
ans=max(ans,x);
modify(a[i],x);
}
cout<<ans<<endl;
return 0;
}
inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}