Pagini recente » Istoria paginii utilizator/radu10 | Diferente pentru problema/fnaf intre reviziile 24 si 23 | Statistici george liutic (george_extreme) | Diferente pentru problema/fnaf intre reviziile 23 si 22 | Cod sursa (job #3310435)
//
// main.cpp
// Subsir crescator maximal
//
// Created by Andrada Minca on 13.09.2025.
//
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
vector<long long> v,sc;
int bs(long long x,int st,int dr)
{
while(st<dr)
{
int mid=(st+dr+1)/2;
if(x>v[sc[mid]])st=mid;
else dr=mid-1;
}
return dr+1;
}
int main()
{
int n;
fin>>n;
v.resize(n+1);
sc.resize(n);
int st=0,dr=0;
sc[0]=n;
v[n]=0;
vector<int> sol(n);
for(int i=0;i<n;i++)
{
fin>>v[i];
int poz=bs(v[i],st,dr);
if(poz>dr||v[sc[poz]]>v[i])
{
sc[poz]=i;
}
if(poz>dr)
{
dr++;
sol[dr]=v[i];
int ind=dr-1;
while(ind>0&&sol[ind]!=sc[ind]){sol[ind]=v[sc[ind]];ind--;}
}
}
fout<<dr<<'\n';
for(int i=1;i<=dr;i++)fout<<sol[i]<<" ";
return 0;
}