Pagini recente » Monitorul de evaluare | Cod sursa (job #1464204) | Cod sursa (job #2530367) | Cod sursa (job #2543320) | Cod sursa (job #1589380)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int NMax = 1e5 + 5;
int l;
int v[NMax], Q[NMax], P[NMax];
inline int Binary(const int &value, int lo, int hi, int &m){
int mid, best;
while(lo <= hi){
mid = (lo + hi) >> 1;
if(lo == hi){
if(lo > m) Q[++m + 1] = INFINITY;
Q[lo] = value;
return lo;
} else {
if(Q[mid] >= value){
hi = mid;
} else {
lo = mid + 1;
}
}
}
return 0;
}
int main(){
int n, m;
fin >> n;
for(int i = 1; i <= n; i++){
fin >> v[i];
}
m = 0;
Q[1] = INFINITY;
for(int i = 1; i <= n; i++){
P[i] = Binary(v[i], 1, m + 1, m);
}
fout << m << "\n";
for(int i = m; i >= 1; i--){
while(P[n] != i) n--;
Q[i] = v[n];
}
for(int i = 1; i <= m; i++){
fout << Q[i] << " ";
}
return 0;
}