Pagini recente » Cod sursa (job #41894) | Cod sursa (job #1239865) | Cod sursa (job #2585517) | Cod sursa (job #1801008) | Cod sursa (job #2126286)
#include <bits/stdc++.h>
#if 1
#define pv(x) cout<<#x<<" = "<<x<<"; ";cout.flush()
#define pn cout<<endl
#else
#define pv(x)
#define pn
#endif
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
#define pb push_back
const int NMax = 1e5 + 5;
const int inf = 1e9 + 5;
using zint = int;
int N,nrSol;
int v[NMax],pre[NMax],sol[NMax];
void print(int);
int main() {
in>>N;
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;
}
void print(int idx) {
if (idx == 0) {
return;
}
print(pre[idx]);
out<<v[idx]<<' ';
}