HDU 5773 the all-purpose Zero longest ascending subsequence + tree array

Source: Internet
Author: User
Tags pow

Title Link: Hdu 5773 the all-purpose Zero

The official puzzle: 0 can be converted to any integer, including negative numbers, obviously to find the LIS as far as possible to put 0 in must be correct.

So we can take 0 out of the remaining to do O (Nlogn) of the LIS, the statistical results of the time to calculate the number of 0.

In order to guarantee the strict increment, we can subtract each weight value s[i] minus I front 0 number, then do LIS, can guarantee the result is strictly increment.

Personal view: For the obvious put so 0 in the part I explained:

    • If the 0 bits are on either side of the longest ascending subsequence, the two 0 must be added in the obvious
    • If there is a 0 sandwiched between the longest ascending sub-sequence, then the number of the 0 left in the LIS should be smaller than the number of 0 to the right 1, and because of the preprocessing effect, the number of the right is at least 2 greater than the number on the left, so 0 can be inserted, for example: 1 2 3 0 4 5 6-> after preprocessing: 1 2 3 0 3 4 5, the longest is 1 2 3 0 4 (5) 5 (6), in parentheses is the original number, in this case 0 is the replacement of the original sequence 0 to the right of 4
    • There are a lot of 0 clips in Lis, the same can be
/************************************************************** problem:hdu 5773 the All-purpose Zero User:youmi language:c++ result:accepted time:171ms memory:3148k******************************************************** ********///#pragma COMMENT (linker, "/stack:1024000000,1024000000")//#include <bits/stdc++.h>#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<stack>#include<Set>#include<sstream>#include<cmath>#include<queue>#include<deque>#include<string>#include<vector>#defineZeros (a) memset (A,0,sizeof (a))#defineOnes (a) memset (A,-1,sizeof (a))#defineSC (a) scanf ("%d", &a)#defineSC2 (A, b) scanf ("%d%d", &a,&b)#defineSC3 (a,b,c) scanf ("%d%d%d", &a,&b,&c)#defineSCS (a) scanf ("%s", a)#defineSclld (a) scanf ("%i64d", &a)#definePT (a) printf ("%d\n", a)#definePtlld (a) printf ("%i64d\n", a)#defineRep (i,from,to) for (int i=from;i<=to;i++)#defineIrep (I,to,from) for (int i=to;i>=from;i--)#defineMax (a) (a) > (b)? ( A):(B))#defineMin (a) < (b) ( A):(B))#defineLson (step<<1)#defineRson (lson+1)#defineEPS 1e-6#defineOO 0x3fffffff#defineTEST cout<< "*************************" <<endlConst DoublePi=4*atan (1.0);using namespaceStd;typedefLong Longll;template<classT> InlinevoidRead (T &N) {    CharCintFlag =1;  for(c = GetChar ();! (c >='0'&& C <='9'|| c = ='-'); c = GetChar ());if(c = ='-') flag =-1, n =0;Elsen = C-'0';  for(c = GetChar (); C >='0'&& C <='9'; c = GetChar ()) n = n *Ten+ C-'0'; N *=Flag;}intPow (int Base, ll N,intmo) {    if(n = =0)return 1; if(n = =1)return Base%mo; intTMP = Pow (Base, N >>1, MO); TMP= (LL) TMP * TMP%mo; if(N &1) TMP = (LL) TMP *Base%mo; returntmp;}//***************************intN;Const intmaxn=200000+Ten;intA[MAXN];intVAL[MAXN];intC[MAXN];inttot;intLowbit (intx) {    returnx& (-x);}voidUpdateintTempintx) {     while(x<=tot) {C[x]=Max (c[x],temp); X+=lowbit (x); }}intQueryintx) {    intres=0;  while(x) {res=Max (c[x],res); X-=lowbit (x); }    returnRes;}intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    intt_t; scanf ("%d",&t_t);  for(intKase=1; kase<=t_t;kase++) {SC (n);        Zeros (c); intCnt=0; inttt=0; intu; Rep (I,1, N)            {SC (u); if(u==0) CNT++; Else{A[tt]=u-CNT; VAL[TT]=A[TT]; TT++; }} sort (Val,val+TT); Tot=unique (VAL,VAL+TT)-Val; intans=0; Rep (I,0, tt-1)        {            intTemp=lower_bound (Val,val+tot,a[i])-val+1; intRes=query (temp-1)+1; Ans=Max (ans,res);        Update (RES,TEMP); } printf ("Case #%d:%d\n", kase,ans+CNT); }}

HDU 5773 the all-purpose Zero longest ascending subsequence + tree array

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.