Cod sursa(job #2743177)

Utilizator Ionut2791Voicila Ionut Marius Ionut2791 Data 22 aprilie 2021 17:47:00
Problema Subsir crescator maximal Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.36 kb
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define LSB(a) ((-a) & a)
using namespace std;

#ifdef LOCAL
#define read() ifstream fin("date.in.txt");
#else
#define read() ifstream fin("scmax.in"); ofstream fout("scmax.out");
#endif // LOCAL
read();

const int N = 100005;
int n, AIB[N];
int v[N];
map<int,int> idx;
set<int> vals;

bool cmp(int a, int b) {
    return v[a] < v[b];
}

int countUnder(int pos) {
    int mx = 0;
    while(pos > 0) {
        mx = max(mx, AIB[pos] + 1);
        pos -= LSB(pos);
    }
    return mx;
}

void update(int pos, int mx) {
    while(pos <= n) {
        AIB[pos] = max(AIB[pos], mx);
        pos += LSB(pos);
    }
}


int main() {
    fin >> n;
    for (int i = 1; i <= n; ++i) {
        fin >> v[i];
        vals.insert(v[i]);
    }

    int p = 1;
    for (int x : vals)
          idx[x] = p++;

    for (int i = 1; i <= n; ++i) {
        //cout << v[i] << " " << idx[v[i]] <<  '\n';
        update(idx[v[i]], countUnder(idx[v[i]]));
        /*for (int i = 1; i <= n; ++i) {
            cout << AIB[i] << " ";
        }
        cout << '\n';
*/
    }

    int mx = 0;
    for (int i = 1; i <= n; ++i)
        mx = max(mx, AIB[i]);

    #ifdef LOCAL
    cout << mx << '\n';
    #else
    fout << mx << '\n';
    #endif // LOCAL

    return 0;
}