Pagini recente » Cod sursa (job #2339171) | Cod sursa (job #3278920) | Cod sursa (job #2822674) | Cod sursa (job #51712) | Cod sursa (job #2342761)
#include <bits/stdc++.h>
using namespace std ;
const int NR = 100005 ;
const int oo = ( 1 << 31 ) - 1 ;
ifstream in ( "scmax.in" ) ;
ofstream out ( "scmax.out" ) ;
vector < int > m ( NR , oo ) ;
int a [ NR ] , n , p [ NR ] , r [ NR ] , posj , posmax ;
int dei ( int from , int to , int key )
{
if ( from - to <= 1 )
{
if ( m [ to ] < key ) return to ;
return from ;
}
int mid = ( from + to ) >> 1 ;
if ( key > m [ mid ] ) return dei ( mid , to , key ) ;
if ( key < m [ mid ] ) return dei ( from , mid , key ) ;
if ( key == m [ mid ] ) return dei ( from , mid , key ) ;
}
void print ( int pos )
{
if ( !pos ) return ;
print ( r [ pos ] ) ;
out << a [ pos ] << ' ' ;
}
int main ()
{
in >> n ;
for ( int i = 1 ; i <= n ; ++ i )
{
in >> a [ i ] ;
posj = dei ( 0 , posmax , a [ i ] ) ;
if ( m [ posj + 1 ] > a [ i ] )
{
m [ posj + 1 ] = a [ i ] ;
posmax = max ( posmax , posj + 1 ) ;
p [ posj + 1 ] = i ;
r [ i ] = p [ posj ] ;
}
}
out << posmax << '\n' ;
print( p [ posmax ] ) ;
}