BZOJ 1109: [POI2007]堆积木Klo (LIS)
mdzz写错变量见祖宗
#include<bits/stdc++.h>
using namespace std;
char cb[1<<15],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<15,stdin),cs==ct)?0:*cs++)
template<class T>inline void read(T &res) {
char ch; int flg = 1; while(!isdigit(ch=getc()))if(ch=='-')flg=-flg;
for(res=ch-'0';isdigit(ch=getc());res=res*10+ch-'0'); res*=flg;
}
const int MAXN = 100005;
int n, m, T[MAXN];
struct node { int x, y; node(){}node(int x, int y):x(x), y(y){} }a[MAXN];
inline bool cmp(const node &A, const node &B) { return A.x == B.x ? A.y < B.y : A.x < B.x; }
inline void chkmax(int &x, int y) { if(y > x) x = y; }
inline void upd(int x, int val) { for(; x <= n; x += x&-x) chkmax(T[x], val); }
inline int qsum(int x) { int re = 0; for(; x; x -= x&-x) chkmax(re, T[x]); return re; }
int main() {
read(n);
int ans = 0;
for(int i = 1, x; i <= n; ++i) {
read(x);
if(i >= x) a[++m] = node(i-x, x);
}
sort(a + 1, a + m + 1, cmp);
for(int i = 1, f_i; i <= m; ++i) {
chkmax(ans, f_i = qsum(a[i].y-1) + 1);
upd(a[i].y, f_i);
}
printf("%d\n", ans);
}