This question thought for 1 hours cannot think out ... The method is really subtle ...
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.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}Const intmaxn=100000+Ten;intT,N,A[MAXN],SUM[MAXN],DP[MAXN];intt[ the*MAXN];voidUpdateintPintValintLintRintRT) { if(L==R) {T[rt]=max (val,t[rt]);return; }intM= (L+R)/2; if(p<=m) Update (P,VAL,L,M,2*RT);ElseUpdate (p,val,m+1R2*rt+1); T[RT]=max (t[2*rt],t[2*rt+1]);}int Get(intLintRintLintRintRT) { if(L<=L&&R<=R)returnT[RT];intM= (L+R)/2, maxl=0, maxr=0; if(l<=m) maxl=Get(L,r,l,m,2*RT);if(r>m) maxr=Get(l,r,m+1R2*rt+1); returnMax (MAXL,MAXR);}intMain () {scanf ("%d", &t);intcas=1; while(t--) {memset (DP,0,sizeofDP); memset (SUM,0,sizeofSUM); memset (T,0,sizeoft); scanf ("%d", &n); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); for(intI=1; i<=n;i++) {sum[i]=sum[i-1];if(a[i]==0) sum[i]++; } for(intI=1; i<=n;i++) { if(a[i]==0)Continue; A[i]=a[i]-sum[i]+1000000; if(a[i]!=0) dp[i]=Get(0, a[i]-1,0,2000000,1)+1;Elsedp[i]=1; Update (A[i],dp[i],0,2000000,1); } intmax=0; for(intI=1; i<=n;i++) max=Max (max,dp[i]); printf ("Case #%d:%d\n", cas++,max+Sum[n]); } return 0;}
HDU 5773 the all-purpose Zero