Cod sursa(job #2432912)

Utilizator andrei42Oandrei42O andrei42O Data 25 iunie 2019 14:04:59
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int N = 100010;
int n,x[N],p[N],v[N],b[N],lo,hi,mi,lmax;
void afisare(int);
int main()
{
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>x[i];
        lo=0;hi=lmax+1;
        while(hi-lo>1)
        {
            mi=(lo+hi)/2;
            if(v[mi]<x[i])
                lo=mi;
            else
                hi=mi;
        }
        v[hi]=x[i];
        p[hi]=i;
        b[i]=p[lo];
        if(hi>lmax)lmax++;
    }
    g<<lmax<<'\n';
    afisare(p[lmax]);
    return 0;
}
void afisare(int i)
{
    if(!i)return;
    afisare(b[i]);
    g<<x[i]<<' ';
}