শুক্রবার, ২৬ মে, ২০১৭

UVA 481 - What Goes Up

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
const long  maxn = 1000010;
long x[maxn],i,n,length=0,increasingSub[maxn],parent[maxn],LIS[maxn],j;
long lis(long x[])
{
    for(i=0; i<n; i++)
    {
        long low=1;
        long  high=length;
        while(low <= high)
        {
            long mid =(low + high)/2;
            if(x[increasingSub[mid]] < x[i])
                low = mid + 1;
            else
                high = mid - 1;
        }
        long pos = low;
        parent[i] = increasingSub[pos-1];
        increasingSub[pos] =  i;
        if(pos > length)
            length=pos;
    }
    long  k=increasingSub[length];
    for(j=length-1; j>=0; j--)
    {
        LIS[j] =  x[k];
        k = parent[k];
    }
    printf("%ld\n-\n",length);
    for(i=0; i<length; i++)
    {
        printf("%ld\n",LIS[i]);
    }

}
main()
{
    n=0;
    long i1,a;
    for(i1=0;;i1++)
    {
        if(scanf("%ld",&a)!=1)
        {
            break;
        }
        x[n++]=a;
    }
    long long ll=lis(x);
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factorization with prime Sieve

vector <int> prime; char sieve[1000009]; int N=1000009; void primeSieve ( ) { sieve[0] = sieve[1] = 1; prime.push_back(2); ...