Pagini recente » Cod sursa (job #2267790) | Cod sursa (job #631502) | Cod sursa (job #504104) | Cod sursa (job #219117) | Cod sursa (job #1973718)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
#define pb push_back
typedef long long ll;
const int NMax = 1e5 + 5;
const int inf = 1e9 + 5;
int N,nrSol;
int v[NMax],sol[NMax],pre[NMax];
void print(int p) {
if (p == 0) {
return;
}
print(pre[p]);
out<<v[p]<<' ';
}
int main() {
in>>N;
nrSol = 0;
for (int i=1;i<=N;++i) {
in>>v[i];
int pw = 1;
for (;pw <= nrSol;pw <<= 1) ;
pw >>= 1;
int pos = 0;
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;
}