POJ 1631 Bridging signals

  这道题之前做过。左边线柱是升序排列的,所以要找右边线柱的最长升序列,

因为最大范围是N = 40000,所以只能用o(nlogn)的写法。

/*Accepted 296K 125MS C++ 581B 2012-04-22 19:00:19 */



#include<cstdio>

#include<cstring>

#include<cstdlib>

#define MAXN 40005

int s[MAXN], top, t, n;

int main()

{

    int T;

    scanf( "%d", &T);

    while( T --)

    {

        scanf( "%d", &n);

        n --;

        top = 1;

        scanf( "%d", &t);

        s[top ++] = t;

        while( n --)

        {

            scanf( "%d", &t);

            if( t > s[top - 1]) s[top ++] = t;

            else {

                int l = 1, r = top - 1;

                while( l <= r)

                {

                    int mid = ( l + r) >> 1;

                    if( s[mid] >= t)

                        r = mid - 1;

                    else l = mid + 1;

                }

                s[l] = t;

            }

        }

        printf( "%d\n", top - 1);

    }

    return 0;

}

 

你可能感兴趣的:(Signal)