Pagini recente » Cod sursa (job #1380081) | Cod sursa (job #2541207) | Cod sursa (job #2753862) | Cod sursa (job #3245649) | Cod sursa (job #535065)
Cod sursa(job #535065)
#include <vector>
#include <fstream>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;
vector< int > v, TopMax, f;
inline void output( ostream& out, int x )
{
if( x )
{
output( out, f[x] );
out<<x<<'\n';
}
}
int main( void )
{
int N, i, left, middle, right;
ifstream in( "scmax.in" );
in>>N;
copy( istream_iterator<int>(in), istream_iterator<int>(), back_inserter(v) );
TopMax.push_back(0);
f.push_back(0);
for( i=1; i < N; ++i )
{
left=0; right=TopMax.size()-1;
while( left < right )
{
middle=(left+right)>>1;
if( v[TopMax[middle]] == v[i] )
{
left=middle;
continue;
}
if( v[TopMax[middle]] > v[i] )
right=middle;
else left=middle+1;
}
f.push_back(0);
if( v[TopMax[left]] > v[i] )
{
if( left >= 1 )
f[i]=TopMax[left];
TopMax[left]=i;
}
else TopMax.push_back(i);
}
ofstream out( "scmax.out" );
out<<TopMax.size()<<'\n';
output( out, TopMax.back() );
return EXIT_SUCCESS;
}