Cod sursa(job #1053467)

Utilizator sebinechitasebi nechita sebinechita Data 12 decembrie 2013 19:23:58
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.93 kb
//nu ii frumos sa te uiti pe sursele altora:))...hotule....nu o sti face singur?:))
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
FILE *fin=fopen("scmax.in", "r");
ofstream fout("scmax.out");
#define MAX 100010

const unsigned maxb=8192;
char buf[maxb];
unsigned ptr=maxb;

inline int getInt(){
    int nr=0,mul=1;
    while(buf[ptr]<'0'||'9'<buf[ptr]||buf[ptr]=='-'){
        if(buf[ptr]=='-'){
            mul=-1;
        }
        if(++ptr>=maxb)
            fread(buf,maxb,1,fin),ptr=0;
    }
    while('0'<=buf[ptr]&&buf[ptr]<='9'){
        nr=nr*10+buf[ptr]-'0';
        if(++ptr>=maxb)
            fread(buf,maxb,1,fin),ptr=0;
    }
    return nr*mul;
}

int AIB[MAX], n, v[MAX], rez[MAX], cpy[MAX];
int a[MAX];

int cauta(int p)
{
    int m=0;
    while(p)
    {
        if(AIB[p]>m)
            m=AIB[p];
        p-=(p&(-p));
    }
    return m;
}

void introdu(int p, int val)
{
    while(p<=n)
    {
        AIB[p]=max(AIB[p], val);
        p+=(p&(-p));
    }
}

int main()
{
    n=getInt();
    int i;

    for(i=1;i<=n;i++)
    {
        a[i]=getInt();
        cpy[i]=a[i];
    }
    //inc normalizare
    sort(a+1, a+n+1);
    return 0;
    int k=1;
    for(i=2;i<=n;i++)
    {
        if(a[i]!=a[k])
            a[++k]=a[i];
    }

    for(i=1;i<=n;i++)
    {
        v[i]=lower_bound(a+1, a+k+1, cpy[i])-a;
    }
    for(i=1;i<=n;i++)
        a[i]=v[i];
    //sf normalizare
    int maxi=1;
    for(i=1;i<=n;i++)
    {
        v[i]=cauta(a[i]-1)+1;
        introdu(a[i], v[i]);
        if(v[i]>v[maxi])
            maxi=i;
    }
    fout<<v[maxi]<<"\n";
    int g=0;
    rez[++g]=cpy[maxi];
    for(i=maxi;i>=1 && v[maxi]>1;i--)
    {
        if(v[i]==v[maxi]-1 && a[i]<a[maxi])
        {
            rez[++g]=cpy[i];
            maxi=i;
        }
    }
    for(i=g;i>=1;i--)
    {
        fout<<rez[i]<<" ";
    }

}