Cod sursa(job #1394996)

Utilizator sergiunascaSergiu Nasca sergiunasca Data 20 martie 2015 21:54:54
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.46 kb
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#define INF (1<<30)
using namespace std;
typedef struct
{
    int nr,numere,poz;
}Compoz;
typedef struct
{
    bool operator()(const Compoz A,const Compoz B)
    {
        return A.nr<B.nr;
    }
}Lower;
std::vector< Compoz > a;
std::vector< Compoz >::iterator xy;
std::vector< int > b,c;
int n,x;
Compoz aux,maxim;
void afisare(int poz)
{
    if(c[poz]!=0)afisare(c[poz]);
    printf("%d ",b[poz]);
}
int main()
{
    freopen("scmax.in","r",stdin);
    freopen("scmax.out","w",stdout);
    scanf("%d",&n);
    aux.nr = -INF;aux.numere = 0;aux.poz = 0;
    a.push_back( aux );
    aux.nr = INF;aux.numere = 0;aux.poz = 0;
    a.push_back( aux );
    b.push_back(0);
    c.push_back(0);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&x);
        b.push_back(x);
        aux.nr = x;
        xy = lower_bound(a.begin(),a.end(),aux,Lower());
        if((*(xy-1)).nr==-INF)
        {
            aux.nr = x;aux.numere = 1;aux.poz = i;
            a.insert( xy , aux );
            c.push_back(0);
        }
        else
        {
            c.push_back((*(xy-1)).poz);
            (*(xy-1)).nr = x;
            (*(xy-1)).numere += 1;
            (*(xy-1)).poz = i;
            if(maxim.nr<(*(xy-1)).nr)
            {
                maxim = (*(xy-1));
            }
        }
    }
    printf("%d\n",maxim.numere);
    afisare(maxim.poz);
    return 0;
}