【题意】

n个数的序列,删除一个数后序列左移,求最后满足i==a[i]的最大个数。

【思路】

设最终得到a[i]==i的序列为s,则s应满足:

i<j,a[i]<a[j],i-a[i]<=j-a[j]

  最后一项代表后边的移动距离不少于前边的。

因为i=i-a[i]+a[i]

所以只要满足i-a[i]单调不减,a[i]单调递增则i一定递增。

则问题转化为一个二维偏序问题,O(nlogn)求LIS。用个BIT即可。

【代码】

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long ll;
const int N = 2e5+; struct Node {
int a,b;
bool operator <(const Node& rhs) const {
if(a!=rhs.a) return a<rhs.a;
else return b<rhs.b;
}
}ns[N]; int C[N],mx;
void upd(int x,int v) {
for(;x<=mx;x+=x&-x)
C[x]=max(C[x],v);
}
int query(int x) {
int res=;
for(;x;x-=x&-x)
res=max(res,C[x]);
return res;
} ll read() {
char c=getchar(); ll f=,x=;
while(!isdigit(c)) {
if(c=='-') f=-;
c=getchar();
}
while(isdigit(c))
x=x*+c-'',
c=getchar();
return x*f;
} int n,a[N]; int main()
{
//freopen("klo.in","r",stdin);
//freopen("klo.out","w",stdout);
n=read();
int tot=;
for(int i=;i<=n;i++) {
a[i]=read();
mx=max(mx,a[i]);
if(i>=a[i])
ns[++tot].a=i-a[i],ns[tot].b=a[i];
}
sort(ns+,ns+tot+);
int ans=;
for(int i=;i<=tot;i++) {
int x=query(ns[i].b-)+;
ans=max(ans,x);
upd(ns[i].b,x);
}
printf("%d\n",ans);
return ;
}

P.S.感觉挺巧妙的 %%%

bzoj 1109 [POI2007]堆积木Klo(LIS)的更多相关文章

  1. BZOJ 1109 POI2007 堆积木Klo LIS

    题目大意:给定一个序列,能够多次将某个位置的数删掉并将后面全部数向左串一位,要求操作后a[i]=i的数最多 首先我们如果最后a[i]=i的数的序列为S 那么S满足随着i递增,a[i]递增(相对位置不变 ...

  2. BZOJ 1109: [POI2007]堆积木Klo

    1109: [POI2007]堆积木Klo Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 948  Solved: 341[Submit][Statu ...

  3. BZOJ.1109.[POI2007]堆积木Klo(DP LIS)

    BZOJ 二维\(DP\)显然.尝试换成一维,令\(f[i]\)表示,强制把\(i\)放到\(a_i\)位置去,现在能匹配的最多数目. 那么\(f[i]=\max\{f[j]\}+1\),其中\(j& ...

  4. BZOJ 1109 [POI2007]堆积木Klo(树状数组)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1109 [题目大意] Mary在她的生日礼物中有一些积木.那些积木都是相同大小的立方体. ...

  5. 1109: [POI2007]堆积木Klo

    1109: [POI2007]堆积木Klo https://lydsy.com/JudgeOnline/problem.php?id=1109 分析: 首先是dp,f[i]表示到第i个的最优值,f[i ...

  6. 【BZOJ】1109: [POI2007]堆积木Klo

    题意 \(n(1 \le n \le 100000)\)个数放在一排,可以一走一些数(后面的数向前移),要求最大化\(a_i=i\)的数目. 分析 分析容易得到一个dp方程. 题解 \(d(i)\)表 ...

  7. 【BZOJ1109】[POI2007]堆积木Klo 二维偏序

    [BZOJ1109][POI2007]堆积木Klo Description Mary在她的生日礼物中有一些积木.那些积木都是相同大小的立方体.每个积木上面都有一个数.Mary用他的所有积木垒了一个高塔 ...

  8. BZOJ1109 : [POI2007]堆积木Klo

    f[i]表示第i个在自己位置上的最大值 则f[i]=max(f[j])+1 其中 j<i a[j]<a[i] a[i]-a[j]<=i-j -> j-a[j]<=i-a[ ...

  9. 【bzoj1109】[POI2007]堆积木Klo 动态规划+树状数组

    题目描述 Mary在她的生日礼物中有一些积木.那些积木都是相同大小的立方体.每个积木上面都有一个数.Mary用他的所有积木垒了一个高塔.妈妈告诉Mary游戏的目的是建一个塔,使得最多的积木在正确的位置 ...

随机推荐

  1. MFC、WTL、WPF、wxWidgets、Qt、GTK、Cocoa、VCL 各有什么特点?

    WTL都算不上什么Framework,就是利用泛型特性对Win API做了层封装,设计思路也没摆脱MFC的影响,实际上用泛型做UI Framework也只能算是一次行为艺术,这个思路下继续发展就会变得 ...

  2. button 事件属性

  3. 77. Combinations

    题目: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For ex ...

  4. Linux进程的睡眠和唤醒简析

    COPY FROM:http://www.2cto.com/os/201204/127771.html 1 Linux进程的睡眠和唤醒 在Linux中,仅等待CPU时间的进程称为就绪进程,它们被放置在 ...

  5. 使用HttpClient发送HTTPS请求以及配置Tomcat支持SSL

    这里使用的是HttpComponents-Client-4.1.2 package com.jadyer.util; import java.io.File; import java.io.FileI ...

  6. OutputStream窥探

    /* * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...

  7. Python3 学习第三弹:异常情况如何处理?

    python 的处理错误的方式: 1> 断言 assert condition 相当于 if not condition: crash program 断言设置的目的就是因为与其让程序晚点崩溃, ...

  8. iOS开发:在Swift中调用oc库

    先列举这个工程中用到的oc源码库: MBProgressHUD:半透明提示器,Loading动画等 SDWebImage:图片下载和缓存的库 MJRefresh: 下拉刷新,上拉加载 Alamofir ...

  9. ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能

    参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-method ...

  10. jquery live hover绑定方法

    $(".select_item span").live({ mouseenter: function() { $(this).addClass("hover") ...