2017 ACM/ICPC Asia Regional Shenyang Online [Cloned]超级简单的LIS

#include
int main()
{
    int n,k,a[100005],b,l,r,top1,top2,mid,c[100005];

    int t;
    scanf("%d",&t);
    while(t--)
    {
        top1=0;
        top2=0;
        a[0]=999999;
        c[0]=-1;
        scanf("%d%d",&n,&k);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&b);
            if(b<=a[top1])//非上升和非下降就是这样
            {
                top1++;
                a[top1]=b;
            }
            else
            {
                l=1;
                r=top1;
                while(l<=r)
                {
                    mid=(l+r)/2;
                    if(b=c[top2])
            {
                top2++;
                c[top2]=b;
            }
            else
            {
                l=1;
                r=top2;
                while(l<=r)
                {
                    mid=(l+r)/2;
                    if(b>c[mid])
                    {
                        l=mid+1;
                    }
                    else r=mid-1;
                }
                c[l]=b;
            }
        }
        
        if(top1+k>=n||top2+k>=n) printf("A is a magic array.\n");
        else printf("A is not a magic array.\n");
    }



}

 

你可能感兴趣的:(2017 ACM/ICPC Asia Regional Shenyang Online [Cloned]超级简单的LIS)