首先我们要保证a[i]是递增的…然后还有保证i-a[i]也是不减的…
然后我们发现这是一个三维偏序的东西…然后再看一看i-a[i]发现其实是个二维偏序,因为a[i]递增i-a[i]不减的时候i必定递增…
所以我们有a[i]作为下标,求一个LIS就可以了
代码如下:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1000000+5;
int n,tr[maxn],cnt,maxnum;
struct M{
int x,y;
friend bool operator < (M a,M b){
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
}s[maxn];
inline void insert(int x,int y){
for(;x<=maxnum;x+=x&(-x))
tr[x]=max(tr[x],y);
}
inline int query(int x){
int res=0;
for(;x;x-=x&(-x))
res=max(res,tr[x]);
return res;
}
signed main(void){
scanf("%d",&n);cnt=0;maxnum=0;
for(int i=1,x;i<=n;i++){
scanf("%d",&x);
if(i>=x)
s[++cnt].x=i-x,s[cnt].y=x,maxnum=max(maxnum,x);
}sort(s+1,s+cnt+1);int ans=0;
for(int i=1;i<=cnt;i++){
int tmp=query(s[i].y-1)+1;
ans=max(ans,tmp);insert(s[i].y,tmp);
}
printf("%d\n",ans);
return 0;
}
by >_< NeighThorn
本文探讨了在特定条件下寻找最长递增子序列(LIS)的问题,并通过巧妙地利用一维和二维偏序特性简化问题。针对输入序列,文章提出了一种有效的算法实现方案,通过维护一个树状数组来动态更新最长递增子序列的长度。
735

被折叠的 条评论
为什么被折叠?



