Pagini recente » soldiers | Cod sursa (job #1709069) | Cod sursa (job #1993818) | Cod sursa (job #79766) | Cod sursa (job #1244664)
#include <fstream>
#include <algorithm>
using namespace std;
const char InFile[]="scmax.in";
const char OutFile[]="scmax.out";
const int MaxN=100111;
ifstream fin(InFile);
ofstream fout(OutFile);
int N,solind,myprev[MaxN],V[MaxN],P[MaxN],best[MaxN],AIB[MaxN];
struct CMP
{
inline bool operator() (const int &A, const int &B)
{
if(V[A]==V[B])
{
return A>B;
}
return V[A]<V[B];
}
};
void afis(int solind)
{
if(!solind)
{
return;
}
afis(myprev[solind]);
fout<<V[P[solind]]<<" ";
}
inline int LSB(const int &x)
{
return x&(-x);
}
inline void UpdateAIB(int pos)
{
int ind=pos;
int val=best[pos];
for(;pos<MaxN;pos+=LSB(pos))
{
if(best[AIB[pos]]<val)
{
AIB[pos]=ind;
}
}
}
inline int QueryAIB(int pos)
{
int sol=0;
for(;pos;pos-=LSB(pos))
{
if(best[AIB[pos]]>best[sol])
{
sol=AIB[pos];
}
}
return sol;
}
int main()
{
fin>>N;
for(int i=1;i<=N;++i)
{
fin>>V[i];
P[i]=i;
}
fin.close();
sort(P+1,P+1+N,CMP());
for(int i=1;i<=N;++i)
{
myprev[P[i]]=QueryAIB(P[i]);
best[P[i]]=best[myprev[P[i]]]+1;
UpdateAIB(P[i]);
if(best[solind]<best[P[i]])
{
solind=P[i];
}
}
fout<<best[solind]<<"\n";
afis(solind);
return 0;
}