Pagini recente » Cod sursa (job #3778) | Cod sursa (job #819094) | Cod sursa (job #2584254) | Cod sursa (job #2978607) | Cod sursa (job #1477497)
#include <fstream>
#include <unordered_map>
using namespace std;
typedef int var;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int V[200000], SCM[200000], Parent[200000];
struct ArbInt {
#define zeros(a) (a&-a)
unordered_map<int, int> T;
void insert(int poz, int val) {
for(;poz>0; poz += zeros(poz))
if(SCM[T[poz]] < SCM[val])
T[poz] = val;
}
int query(int poz) {
int r = 0;
for(;poz;poz-=zeros(poz))
if(SCM[r] < SCM[T[poz]])
r = T[poz];
return r;
}
};
ArbInt T;
void afis(int node) {
if(Parent[node]) afis(Parent[node]);
fout<<V[node]<<" ";
}
int main() {
int n, val;
fin>>n;
int start = 0;
for(int i=1; i<=n; i++) {
fin>>V[i];
Parent[i] = T.query(V[i] - 1);
SCM[i] = 1 + SCM[Parent[i]];
if(SCM[start] < SCM[i])
start = i;
T.insert(V[i], i);
}
fout<<SCM[start]<<'\n';
afis(start);
return 0;
}