Pagini recente » Cod sursa (job #2542760) | Cod sursa (job #628405) | Cod sursa (job #2672638) | Cod sursa (job #653140) | Cod sursa (job #2560977)
#include <iostream>
#include <fstream>
#include <algorithm>
#define zeros(x) (x^(x-1)&x)
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n, i, h = 1, v[100010], AIB[100010], lst[100010], D[100010], up[100010], bst;
void update(int x, int ind)
{
for (int i = x; i <= n; i += zeros(i))
if (D[ind] > D[AIB[i]])
AIB[i] = ind;
}
int query(int x)
{
int mx = 0;
for (int i = x; i >= 1; i -= zeros(i))
if (D[AIB[i]] > D[mx])
mx = AIB[i];
return mx;
}
int main()
{
f >> n;
for (i = 1; i <= n; ++i)
{
f >> v[i];
lst[i] = v[i];
}
sort(lst + 1, lst + n + 1);
for (i = 2; i <= n; ++i)
if (lst[i] != lst[h])
lst[++h] = lst[i];
for (i = 1; i <= n; ++i)
v[i] = lower_bound(lst + 1, lst + h + 1, v[i]) - lst;
for (i = 1; i <= n; ++i)
{
up[i] = query(v[i] - 1);
D[i] = D[up[i]] + 1;
update(v[i], i);
}
for (i = 1; i <= n; ++i)
if (D[i] > D[bst])
bst = i;
g << D[bst];
return 0;
}