Cod sursa(job #2635452)

Utilizator mateilazarescumateilazarescu mateilazarescu Data 14 iulie 2020 15:28:50
Problema Subsir crescator maximal Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.03 kb

#include<fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
long long v[100004],t[100004],r[100004];
long long n,i,len,st,dr,mij,elem;
int main()
{
    fin>>n;
    for(i=1;i<=n;i++) fin>>v[i];
    len=1;
    t[1]=1;
    for(i=2;i<=n;i++)
    {
        if(v[i]>v[t[len]])
        {
            len++;
            t[len]=i;
            r[i]=t[len-1];
        }
        else
        {
        st= 1;
        dr = len;
        while (st < dr)
        {
            int mij = (st + dr) / 2;
            if (v[i] > v[t[mij]])
                st = mij + 1;
            else
                dr = mij;
        }
            mij=st;
            t[mij]=i;
            r[i]=t[mij-1];
        }
    }
    fout<<len<<'\n';
    return 0;
}

/*#include <bits/stdc++.h>

using namespace std;

#define N 100005

ifstream fin ("scmax.in");

ofstream fout ("scmax.out");

int a[N];

int aux[N];

int cur[N];

int ant[N];

int l = 0;

int n;

int cauta (int x, int lun)

{

    int st, dr;

        st= 1;
        dr = lun;
        while (st < dr)
        {
            int mij = (st + dr) / 2;
            if (x > aux[mij])
                st = mij + 1;
            else
                dr = mij;
        }

    return st;

}

void tipar (int poz)

{

    if (poz == 0)

        return;

    else

    {

        tipar (ant[poz]);

        fout << a[poz] << " ";

    }

}

int main ()

{

    fin >> n;

    for (int i = 1; i <= n; i++)

        fin >> a[i];

    aux[1] = a[1];

    cur[1] = 1;

    l++;

    for (int i = 2; i <= n; i++)

    {

         int x = cauta (a[i], l);

         if (a[i] > aux[x])

         {

            aux[++l] = a[i];

            cur[l] = i;

            ant[i] = cur[l - 1];

         }

         else

         {

            aux[x] = a[i];

            cur[x] = i;

            ant[i] = cur[x - 1];

         }

    }

    fout << l << "\n";

    tipar (cur[l]);

}
*/