我们设f[i]为保留第i个木块最多的符合未知数
显然f[i]=max(f[j])+1 满足i>j a[i]>a[j] i-j>=a[i]-a[j]
我们把最后一个式子变成a[i]-i<=a[j]-j
三元关系很不好弄对吧,但仔细观察可知,由最后两个式子一定可以推出i>j
那不就水了,排序树状数组即可
1 var f,a,b:array[0..100010] of longint; 2 c:array[0..1000010] of longint; 3 i,n,ans:longint; 4 5 function max(a,b:longint):longint; 6 begin 7 if a>b then exit(a) else exit(b); 8 end; 9 10 function lowbit(x:longint):longint;11 begin12 exit(x and (-x));13 end;14 15 procedure swap(var a,b:longint);16 var c:longint;17 begin18 c:=a;19 a:=b;20 b:=c;21 end;22 23 procedure add(x,w:longint);24 begin25 while x<=n do26 begin27 c[x]:=max(c[x],w);28 x:=x+lowbit(x);29 end;30 end;31 32 function ask(x:longint):longint;33 begin34 ask:=0;35 while x>0 do36 begin37 ask:=max(ask,c[x]);38 x:=x-lowbit(x);39 end;40 end;41 42 procedure sort(l,r:longint);43 var y,i,j,x:longint;44 begin45 i:=l;46 j:=r;47 x:=a[(l+r) shr 1];48 y:=b[(l+r) shr 1];49 repeat50 while (b[i]>y) or (b[i]=y) and (a[i]b[j]) or (b[j]=y) and (x j) then53 begin54 swap(a[i],a[j]);55 swap(b[i],b[j]);56 inc(i);57 dec(j);58 end;59 until i>j;60 if l 0 then continue;75 f[i]:=ask(a[i]-1)+1;76 ans:=max(f[i],ans);77 add(a[i],f[i]);78 end;79 writeln(ans);80 end.