Sol
Sort + Tree-like array.
We need to find a maximum sequence that satisfies the following conditions.
\ (j-w[j]<=i-w[i],j<i,w[j]<w[i]\)
is to maintain the longest ascending subsequence of a partial-order set, and then the first and third formulas add up to the second, then the two-dimensional partial order, which is maintained by a tree array.
Code
/************************************************************** problem:1109 User:beiyu language:c++ Result : Accepted time:292 ms memory:2464 kb****************************************************************/#include <c stdio> #include <utility> #include <algorithm> #include <iostream>using namespace std; const int N = 100005; #define MPR (A, B) (W) {A, b} int n,ans;int d[n];struct w{int x, y;} A[n];bool operator < (const W &a,const w &b) {return a.y==b.y?a.x<b.x:a.y<b.y;} inline int in (int x=0,ch Ar Ch=getchar ()) {while (ch> ' 9 ' | | ch< ' 0 ') Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') x= (x<<3) + (x<<1) +ch-' 0 ', Ch=getchar (); return x; } int Sum (int x,int res=0) {if (!x) return res;for (; x;x-=x&-x) Res=max (res,d[x]); return res;} void Add (int x,int v) {for (; x<=n;x+=x&-x) D[x]=max (d[x],v);} int main () {//Freopen ("In.in", "R", stdin); N=in (); for (int i=1,x;i<=n;i++) x=in (), A[I]=MPR (x,i-x); Sort (a+1,a+N+1); for (int i=1;i<=n;i++) {if (a[i].y<0) continue; int Tmp=sum (a[i].x-1) +1; Ans=max (Tmp,ans); ADD (A[I].X,TMP); }cout<<ans<<endl; return 0;}
Bzoj 1109: [POI2007] Stacked wood klo