Pagini recente » Cod sursa (job #3193249) | Cod sursa (job #2182352) | Cod sursa (job #3204304) | Cod sursa (job #1263188) | Cod sursa (job #1459951)
#include<fstream>
#include<algorithm>
using namespace std;
#define MAX 100001
ifstream in("scmax.in");
ofstream out("scmax.out");
int AIB[MAX],up[MAX],lst[MAX],v[MAX],R[MAX],N,D[MAX];
int query(int x)
{
int max=0;
for(;x;x-=x&(-x))
if(D[AIB[x]]>D[max])
max=AIB[x];
return max;
}
void update(int x,int ind)
{
for(;x<=N;x+=x&(-x))
if(D[AIB[x]]<D[ind])
AIB[x]=ind;
}
int main()
{
in>>N;
for(int i=1;i<=N;i++)
in>>lst[i],R[i]=lst[i];
sort(lst+1,lst+N+1);
int h=1;
for(int i=2;i<=N;i++)
if(lst[i]!=lst[h])
lst[++h]=lst[i];
for(int i=1;i<=N;i++)
v[i]=lower_bound(lst +1,lst +h+1,R[i]) - lst;
for(int i=1;i<=N;i++)
{
up[i]=query(v[i]-1);
D[i]=D[up[i]]+1;
update(v[i],i);
}
int max=0;
for(int i=1;i<=N;i++)
if(D[i]>D[max])
max=i;
h=0;
out<<D[max]<<endl;
for(int i=max;i;i=up[i])
lst[++h]=R[i];
for(int i=h;i>0;i--)
out<<lst[i]<<" ";
return 0;
}