Cod sursa(job #3252923)

Utilizator Vlad_NistorNIstor Vlad Vlad_Nistor Data 31 octombrie 2024 15:15:32
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;
const int32_t NMAX = 100001;
const string FILEOUT = "scmax.out",
             FILEIN = "scmax.in";


ofstream OUT (FILEOUT);
ifstream IN (FILEIN);

int a[NMAX], dp[NMAX], father[NMAX], Back = 0;


static int32_t cb(int val) {
    int32_t st = 1, dr = Back, mid, poz = 0;
    while(st <= dr) {
        mid = (st + dr ) >> 1;
        if(val > a[dp[mid]]) {
            st = mid + 1;
            poz = mid;
        }else {
            dr = mid - 1;
        }
    }
    return poz;
}

static void print(int Index) {
    if(father[Index])
        print(father[Index]);
    OUT << a[Index] << ' ';
}


int32_t main(void) {
    int n;
    IN >> n;
    for(int i = 1; i <= n; i++) {
        IN >> a[i];
        int last = cb(a[i]);
        Back = max(Back, last + 1);
        dp[last + 1 ] = i;
        father[i] = dp[last];
    }
    OUT << Back << endl;
    print(dp[Back]);
}