Cod sursa(job #1164039)

Utilizator UVS_Elfus_Deneo_KiraUVS-Elfus-Dutzul-Kira UVS_Elfus_Deneo_Kira Data 1 aprilie 2014 20:16:00
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.22 kb
#include<fstream>
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#include<queue>
#define f cin
#define g cout
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
#define ll unsigned long long
#define bit (1<<18)
#define inf 1000000
#define N 100100
#define mod 1000000007
#define inu "scmax.in"
#define outu "scmax.out"
using namespace std;
ifstream f(inu);
ofstream g(outu);
//int dx[]={0,0,0,1,-1};
//int dy[]={0,1,-1,0,0};
int t,v[N],s[N],l[N],n,po;
int cb(int x)
{
	int st=1,dr=t,sol=1;
	while(st<=dr)
	{
		int mij=(st+dr)>>1;
		if(x<=s[mij])
		{
			sol=mij;
			dr=mij-1;
		}
		else
			st=mij+1;
	}
	return sol;
}
int main ()
{
	f>>n;
	f>>v[1];
	s[1]=v[1];
	l[1]=1;
	t=1;
	FOR(i,2,n)
	{
		f>>v[i];
		if(v[i]>s[t])
		{
			l[i]=++t;
			s[t]=v[i];
		}
		else
		if(v[i]==s[t])
			l[i]=t;
		else
		{
			po=cb(v[i]);
			l[i]=po;
			s[po]=v[i];
		}
	}
	g<<t<<"\n";
	po=t;
	for(int i=n;i>=1;--i)
	{
		if(l[i]==t)
		{
			s[t]=v[i];
			t--;
		}
	}
	FOR(i,1,po)
	g<<s[i]<<" ";
	return 0;
}