Cod sursa(job #3212461)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 11 martie 2024 19:25:54
Problema Subsir crescator maximal Scor 55
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define dbg(x) cout << #x << ": " << x << "\n";
#define sz(x) ((int)x.size())

using ll = long long;

const string fn = "scmax";
ifstream fin(fn + ".in");
ofstream fout(fn + ".out");
int n;
int a[100005];
int lis[100005], poz[100005];
int main()
{
    fin >> n;
    for (int i = 1; i <= n; ++i)
        fin >> a[i];
    int p = 0;
    for (int i = 1; i <= n; ++i)
        if (a[i] > lis[p])
        {
            lis[++p] = a[i];
            poz[i] = p;
        }
        else
        {
            int pz = lower_bound(lis + 1, lis + p + 1, a[i]) - lis;
            lis[pz] = a[i];
            poz[i] = pz;
        }
    fout << p << '\n';
    vector<int> ans;
    for (int i = n; i >= 1; --i)
        if (poz[i] == p)
            ans.pb(i), --p;
    reverse(ans.begin(), ans.end());
    for (auto i : ans)
        fout << i << ' ';
    return 0;
}