Cod sursa(job #2671649)

Utilizator CiubarLoverBaiatu cu Ciubaru CiubarLover Data 12 noiembrie 2020 15:15:24
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
vector<int>seq[100005];
int n,x,lmax;
int binar(int pos1,int pos2,int nr)
{
    ///cel mai mare index cu o valoare mai mica decat nr
    while(pos2>pos1)
    {
        int mid=(pos2+pos1)/2;
        if (seq[mid][mid]>=nr)
            pos2=mid;
        else
            pos1=mid+1;
    }
    return pos2;
}
int main()
{
    fin>>n;
    fin>>x;
    seq[0].push_back(x);
    lmax=1;
    for(int i=2;i<=n;i++)
    {
        fin>>x;
        int index=binar(0,lmax,x);
        if(index==0)
        {
            seq[0][0]=x;
            continue;
        }
        if(index==lmax)
            lmax++;
        seq[index].clear();
        for(int j=0;j<index;j++)
            seq[index].push_back(seq[index-1][j]);
        seq[index].push_back(x);
    }
    fout<<lmax<<"\n";
    for(int i=0;i<lmax;i++)
        fout<<seq[lmax-1][i]<<" ";
    return 0;
}