Cod sursa(job #2744255)

Utilizator Ionut2791Voicila Ionut Marius Ionut2791 Data 24 aprilie 2021 10:28:06
Problema Subsir crescator maximal Scor 5
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.22 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 = 100005;
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) {
    while(pos <= n) {
        if(last[pos] < act){
            ++AIB[pos];
            last[pos] = act;
        }
        pos += LSB(pos);
    }
}


int main() {
    read();
    fin >> n;
    n = 2 * 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; ++j)
            cout << AIB[j] << " ";
        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;
}