[Luogu 3902]Increasing
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的更多相关文章
- [BZOJ 4403]序列统计
Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第一行包含一个整数T,表示数据组 ...
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- [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 ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 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 ...
- 【LeetCode】Increasing Triplet Subsequence(334)
1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...
- [tem]Longest Increasing Subsequence(LIS)
Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- LintCode-Longest Increasing Subsequence
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
随机推荐
- 【Spring源码深度解析学习系列】容器的基础XmlBeanFactory(二)
一.配置文件封装 Spring的配置文件读取是通过ClassPathResource进行封装的,如new ClassPathResource("test.xml"),那么Class ...
- 【Redis使用系列】Redis常用操作
一.string类型的常用命令 set key value #一个key对应一个value.多次赋值,会覆盖前面. setnx key value #如果key存在则创建key1,并返回1,如果 ...
- Alpha冲刺博客集
传送门 冲刺随笔 Alpha冲刺day1 (10.31):第一天博客地址 Alpha冲刺day2 (11.01):第二天博客地址 Alpha冲刺day3 (11.02):第三天博客地址 Alpha冲刺 ...
- MySQL 服务安装及命令使用
MySQL 服务安装及命令使用 课程来源说明 本节实验后续至第17节实验为本课程的进阶篇,都基于 MySQL 官方参考手册制作,并根据实验楼环境进行测试调整改编.在此感谢 MySQL 的开发者,官方文 ...
- Scrum 冲刺 第三日
Scrum 冲刺 第三日 目录 要求 项目链接 燃尽图 问题 今日任务 明日计划 成员贡献量 要求 各个成员今日完成的任务(如果完成的任务为开发或测试任务,需给出对应的Github代码签入记录截图:如 ...
- 关于第一次使用vue-cli
前段时间终于终于可以用vue-cli,webpack做个企业站,记一下过程... 首先node.js,按照vue官网的步骤命令提示符走一波,网速原因,所以用的是淘宝镜像 cnpm # 全局安装 vue ...
- 【bug清除】Surface Pro系列使用Drawboard PDF出现手写偏移、卡顿、延迟现象的解决方式
最近自己新买的New Surface Pro在使用Drawboard PDF时,出现了性能问题,即笔迹延迟偏移,卡顿的问题. 排查驱动问题之后,确认解决方案如下: 将Surface的电池调到性能模式, ...
- Nginx配置小结
前两天区听了一堂Nginx的课,然后翻了一下自己之前的Nginx的笔记,做了一个简单的小结. 全局变量 $args : 这个变量等于请求行中的参数,同$query_string $content_le ...
- LeetCode & Q13-Roman to Integer-Easy
Math String Description: Given a roman numeral, convert it to an integer. Input is guaranteed to be ...
- 深度学习之 mnist 手写数字识别
深度学习之 mnist 手写数字识别 开始学习深度学习,先来一个手写数字的程序 import numpy as np import os import codecs import torch from ...