Pagini recente » Cod sursa (job #2870415) | Cod sursa (job #1496404) | Cod sursa (job #2076573) | Cod sursa (job #2869859) | Cod sursa (job #1477503)
#include <fstream>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef int var;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int V[200000], SCM[200000], Parent[200000], T[200000], W[200000];
unordered_map<int, int> Map;
#define zeros(a) (a&-a)
void update(int poz, int val) {
for(;poz<=100000; 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;
}
void afis(int i) {
if(Parent[i]) afis(Parent[i]);
fout<<V[i]<<" ";
}
int main() {
int n, i, start = 0, val = 0;
fin>>n;
for(i=1; i<=n; i++)
fin>>V[i], Map[V[i]] = 1;
for(auto &p : Map) W[++start] = p.first;
sort(W+1, W+start+1);
for(i=1; i<=start; i++) Map[W[i]] = i;
for(start=0, i=1; i<=n; i++) {
val = Map[V[i]];
Parent[i] = query(val - 1);
SCM[i] = SCM[Parent[i]] + 1;
if(SCM[start] < SCM[i]) start = i;
update(val, i);
}
fout<<SCM[start]<<'\n';
afis(start);
return 0;
}