Cod sursa(job #2744262)

Utilizator Ionut2791Voicila Ionut Marius Ionut2791 Data 24 aprilie 2021 10:38:06
Problema Subsir crescator maximal Scor 5
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.48 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

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

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

void update(int pos, int act) {
    int have = 1;

    while(pos <= n * 2) {
        if(last[pos] < act){
            ++AIB[pos];
            have = max(AIB[pos], have);
            last[pos] = act;
        }
        else if(AIB[pos] == have)
            last[pos] = min(last[pos], act);
        pos += LSB(pos);
    }
}


int main() {
    read();
    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) {
        update(idx[v[i]], v[i]);

        /*for (int j = 1; j <= n * 2; ++j)
            cout << AIB[j] << " ";
        cout << '\n';

        for (int j = 1; j <= n * 2; ++j)
            cout << last[j] << " ";
        cout << '\n';
        cout << '\n';
        */
    }


    int mx = 0;
    for (int i = 1; i <= n * 2; ++i)
        mx = max(mx, AIB[i]);
    #ifdef LOCAL
    cout << mx << '\n';
    #else
    fout << mx << '\n';
    #endif // LOCAL

    return 0;
}