Pagini recente » Cod sursa (job #188416) | Cod sursa (job #2743074) | Cod sursa (job #3181544) | Cod sursa (job #1007924) | Cod sursa (job #2009274)
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <time.h>
#include <algorithm>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
#define ll long long
#define ui unsigned int
#define pb push_back
const int inf = 1e9 + 5;
const int NMax = 1e5 + 5;
int N,nrSol;
int v[NMax],sol[NMax],pre[NMax];
void print(int);
int main() {
in>>N;
for (int i=1;i <= N;++i) {
in>>v[i];
int pw = 1,pos = 0;
while (pw <= nrSol) {
pw <<= 1;
}
pw >>= 1;
while (pw) {
if (pos + pw <= nrSol && v[sol[pos+pw]] <= v[i]) {
pos += pw;
}
pw >>= 1;
}
if (v[sol[pos]] == v[i]) {
continue;
}
sol[pos+1] = i;
pre[i] = sol[pos];
if (pos == nrSol) {
++nrSol;
}
}
out<<nrSol<<'\n';
print(sol[nrSol]);
in.close();out.close();
return 0;
}
void print(int x) {
if (x == 0) {
return;
}
print(pre[x]);
out<<v[x]<<' ';
}