Pagini recente » Cod sursa (job #2358636) | Cod sursa (job #61990) | Cod sursa (job #2875755) | Cod sursa (job #233912) | Cod sursa (job #1233992)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "scmax.in";
const char outfile[] = "scmax.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
int N, v[MAXN], aib[MAXN], dp[MAXN], res[MAXN], k, last[MAXN];
vector <int> S;
inline int lsb(int x) {
return x & (-x);
}
inline void Update(int x, int ind) {
for(int i = x ; i <= N ; i += lsb(i))
if(dp[aib[i]] < dp[ind])
aib[i] = ind;
}
inline int Query(int x) {
int mx = 0;
for(int i = x ; i > 0 ; i -= lsb(i))
if(dp[mx] < dp[aib[i]])
mx = aib[i];
return mx;
}
inline void Write(int ind) {
if(last[ind])
Write(last[ind]);
fout << res[ind] << ' ';
}
int main() {
cin.sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen(infile, "r", stdin);
freopen(outfile, "w", stdout);
#endif
fin >> N;
for(int i = 1 ; i <= N ; ++ i) {
fin >> v[i];
res[i] = v[i];
S.push_back(v[i]);
}
sort(S.begin(), S.end());
S.resize(unique(S.begin(), S.end()) - S.begin());
for(int i = 1 ; i <= N ; ++ i)
v[i] = 1 + lower_bound(S.begin(), S.end(), v[i]) - S.begin();
int indmax = 1;
for(int i = 1 ; i <= N ; ++ i) {
last[i] = Query(v[i] - 1);
dp[i] = dp[last[i]] + 1;
Update(v[i], i);
if(dp[indmax] < dp[i])
indmax = i;
}
fout << dp[indmax] << '\n';
Write(indmax);
fin.close();
fout.close();
return 0;
}