"Dichotomy", "Longest ascending subsequence" HDU 5489 removed Interval (acm/icpc Asia regional Hefei Online)

Source: Internet
Author: User

Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=5489

Main topic:

A sequence of N (n<=100000) that removes the number of adjacent L (minus the entire interval), making the longest ascending subsequence (LIS) the longest remaining.

Topic Ideas:

"Dichotomy" "Longest ascending subsequence"

First, assuming that the number of [i,i+m-1] L is removed, the remaining LIS length is Max (the last Lis length at the end of the I left is less than a[i+m] +a[i+m] start to the last Lis length).

So we can know the LIS that starts at the end of each number by f[i the length of the longest descent subsequence from N to 1.

Then, from the beginning to do the LIS, while the second in the number of the first I find the last one is smaller than a[i+m] the longest lis length, update the answer.

1 //2 //by Coolxxx3 //#include <bits/stdc++.h>4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <map>9#include <stack>Ten#include <queue> One#include <Set> A#include <bitset> -#include <memory.h> -#include <time.h> the#include <stdio.h> -#include <stdlib.h> -#include <string.h> - //#include <stdbool.h> +#include <math.h> - #defineMin (a) < (b) ( A):(B)) + #defineMax (a) (a) > (b)? ( A):(B)) A #defineABS (a) ((a) >0? ( A):(-(a))) at #defineLowbit (a) (a& (a)) - #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) - #defineMem (A, B) memset (A,b,sizeof (a)) - #defineEPS (1E-8) - #defineJ 10000 in #defineMoD 1000000007 - #defineMAX 0x7f7f7f7f to #definePI 3.14159265358979323 + #defineN 100004 - using namespacestd; thetypedefLong LongLL; * intCas,cass; $ intN,m,lll,ans;Panax Notoginseng LL Aans; - intA[n],f[n],q[n]; the voidGETF () + { A     intI,l,r,mid; theLll=0; +      for(i=n;i;i--) -     { $L=0, r=lll; $          while(l<R) -         { -Mid= (l+r+1) >>1; the             if(Q[mid]>a[i]) l=mid; -             Elser=mid-1;Wuyi         } theq[r+1]=A[i]; -f[i]=r+1; WuLll=max (lll,r+1); -     } About } $ voidWork () - { -     intI,l,r,mid; -Lll=0; A      for(i=1; i+m<=n;i++) +     { theL=0, r=lll; -          while(l<R) $         { theMid= (l+r+1) >>1; the             if(Q[mid]<a[i+m]) l=mid; the             Elser=mid-1; the         } -Ans=max (ans,r+f[i+m]); inL=0, r=lll; the          while(l<R) the         { AboutMid= (l+r+1) >>1; the             if(Q[mid]<a[i]) l=mid; the             Elser=mid-1; the         } +q[r+1]=A[i]; -Lll=max (lll,r+1); the     }Bayians=Max (ans,lll); the } the intMain () - { - #ifndef Online_judge the //freopen ("1.txt", "R", stdin); the //freopen ("2.txt", "w", stdout); the     #endif the     inti,j,k; -      the //for (scanf ("%d", &cass); cass;cass--) the      for(SCANF ("%d", &cas), cass=1; cass<=cas;cass++) the //while (~scanf ("%s", s+1))94 //while (~scanf ("%d", &n)) the     { theans=0; theprintf"Case #%d:", Cass);98scanf"%d%d",&n,&m); About          for(i=1; i<=n;i++) scanf ("%d", A +i); - getf ();101 Work ();102printf"%d\n", ans);103     }104     return 0; the }106 /*107 //108 109 // the */
View Code

"Dichotomy", "Longest ascending subsequence" HDU 5489 removed Interval (acm/icpc Asia regional Hefei Online)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.