Description

Input

Output

Sample Input

3
1 3 2

Sample Output

1

HINT

题解

由于题目要求我们求严格递增的数列,即:

$$A[i]>A[i-1],1<i<=N$$

我们不妨令B[i]=A[i]-i,那么我们容易得到

$$B[i]>=B[i-1],1<i<=N$$

两式是等价的。

那么我们可以将原数列处理一下,我们只需要求出$B[i]$的最长不下降子序列,把不在序列中的那些数$B[i]$都改成符合条件的数(比如说和左边最近一个在最长不下降子序列中的$B[j]$相等)就能满足题意了。

当然,我们并不需要求出具体的修改方案,我们只需要求出最长不下降的长度$K$,输出$N-K$即可。

注意:

由于数据为$10^5$显然我们要用二分优化求最长不下降子序列长度。同时由于减去了$i$,我们需要将数组初始化为极小值。

 #include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define RE register
#define IL inline
using namespace std;
const int N=1e5; int n,x;
int f[N+],maxn; IL int Dev(int x)
{
int l=,r=maxn,mid,ans;
while(l<=r)
{
mid=(l+r)>>;
if (f[mid]<=x) ans=mid,l=mid+;
else r=mid-;
}
return ans;
}
IL int Min(int a,int b) {return a<b ? a:b;} int main()
{
memset(f,,sizeof(f));
scanf("%d",&n);
for (RE int i=;i<=n;i++)
{
scanf("%d",&x);
x-=i;
int tmp=Dev(x);
if (tmp==maxn) f[++maxn]=x;
else f[tmp+]=Min(f[tmp+],x);
}
printf("%d\n",n-maxn);
return ;
}

[Luogu 3902]Increasing的更多相关文章

  1. [BZOJ 4403]序列统计

    Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第一行包含一个整数T,表示数据组 ...

  2. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  3. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  4. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  5. git error: unable to rewind rpc post data - try increasing http.postBuffer

    error: unable to rewind rpc post data - try increasing http.postBuffererror: RPC failed; curl 56 Rec ...

  6. 【LeetCode】Increasing Triplet Subsequence(334)

    1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...

  7. [tem]Longest Increasing Subsequence(LIS)

    Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...

  8. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  9. LintCode-Longest Increasing Subsequence

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

随机推荐

  1. 构造函数与析构函数(construction undergoing)

    构造函数和析构函数 一.构造函数: 1.普通构造函数:在对象被创建时利用特定的值构造对象,将对象初始化到一个特定的状态. 特性:构造函数的函数名和类名相同:没有返回值:在对象被创建时被自动调用:如果有 ...

  2. C语言最后一次博客作业

    1.当初你是如何做出选择计算机专业的决定的? 一开始选专业的时候,说实话我很纠结也很迷茫,对我来说,中学时代,似乎就只要考好试,做好题就可以了,对于未来想要做啥并没有那么多的规划和想法,偶尔跟基友畅聊 ...

  3. 学号:201621123032 《Java程序设计》第1周学习总结

    1:本周学习总结 JDK,JRE,JVM三者的含义和关系.JDK是java开发工具包,包含了java的运行环境,java工具和类文库.例如java.javac.jar....可以把 .java编译成. ...

  4. CocoaPods 基础知识--------安装 及 使用第三方库

    极客学院:http://www.jikexueyuan.com/course/2665_2.html?ss=1

  5. 20145237 《Java程序设计》第九周学习总结

    20145237 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章 整合数据库 JDBC入门 ·数据库本身是个独立运行的应用程序 ·撰写应用程序是利用通信协议对数据库进行指令 ...

  6. hibernate懒加载导致jackjson解析json时StackOverFlow

    @JsonIgnore @JsonFilter @JsonBackReference @JsonManagedReference @JsonIgnoreProperties jackson中的@Jso ...

  7. bzoj千题计划128:bzoj4552: [Tjoi2016&Heoi2016]排序

    http://www.lydsy.com/JudgeOnline/problem.php?id=4552 二分答案 把>=mid 的数看做1,<mid 的数看做0 这样升序.降序排列相当于 ...

  8. 5种做法实现table表格中的斜线表头效果

    table表格,这个东西大家肯定都不陌生,代码中我们时常都能碰到,那么给table加一个斜线的表头有时是很有必要的,但是到底该怎么实现这种效果呢? 我总结了以下几种方法: 1.最最最简单的做法 直接去 ...

  9. wireshark抓包分析tcp连接与断开

    其实对于网络通信的学习,最好还是能够自己抓到包详细地一下,不然只单单通过文字和图的描述印象不够深刻.本文通过实际的抓包操作来看一下tcp的连接与断开是怎样的. 首先需要去https://www.wir ...

  10. Linq 生成运算符 Empty,Range,Repeat

    var c1 = Enumerable.Empty<string>();//c1.Count=0 , );//{9527,9528,9529,......9536} , );//{9527 ...