Bridging signals pku1631

Bridging signals pku1631

#include < iostream >
using   namespace  std;

int  t;
int  n,a;
int  size;
int  c[ 40001 ];
int  cal( int  ai){
    
int  l = 0 ,r = size - 1 ;
    
while (l <= r){
        
int  mid = (l + r) >> 1 ;
        
if (a > c[mid - 1 ] && a <= c[mid])  return  mid;
        
else   if (a > c[mid]) l = mid + 1 ;
        
else  r = mid - 1 ;
    }
}
int  main()
{
    scanf(
" %d " , & t);
    
while (t -- ){
        scanf(
" %d%d " , & n, & a); n -- ;
        c[
0 ] = a; size = 1 ;
        
while (n -- ){
            scanf(
" %d " , & a);
            
int  j;
            
if (a <= c[ 0 ]) j = 0 ;
            
else   if (a > c[size - 1 ]) j = size ++ ;
            
else  j = cal(a);
            c[j]
= a;
        }
        printf(
" %d\n " ,size);
    }
    
return   0 ;
}

你可能感兴趣的:(Bridging signals pku1631)