[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 ...
随机推荐
- 第1次作业:我与我的IT梦
第一部分:结缘计算机 1.1最美的风景,一直在路上 说实话以前没有想过自己将学习计算机这个专业,在大二之前,我还是教师教育学院的一名师范生,机缘巧合,赶上了学校允许师范专业的同学转到非师范专业,于是, ...
- C语言嵌套循环作业
一.PTA实验作业 题目1:7-4 换硬币 1. 本题PTA提交列表 2. 设计思路 1.定义fen5:5分硬币数量, fen2:2分硬币数量, fen1:1分硬币数量, total:硬币总数量,co ...
- Java作业-多线程
未完成,占位以后补 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 书面作业 本次PTA作业题集多线程 源代码阅读:多线程程序BounceThread 1.1 Ball ...
- 项目Alpha冲刺Day2
一.会议照片 二.项目进展 1.今日安排 初步搭建后台框架,根据昨天的最终设计再修改原型,成功使用powerDesigner导出sql. 2.问题困难 使用了比较多的框架,而且是首次尝试纯java配置 ...
- tornado httpserver
# coding:utf-8 import tornado.web import tornado.ioloop import tornado.httpserver # 新引入httpserver模块 ...
- Django 基本设置
建立django目录,为了独立区分app和主站的关系,需要把app完全和主站分离 app/views.py from django.shortcuts import render from djang ...
- Tornado介绍及自定义组件
Tornado 的性能是相当优异的,因为它试图解决一个被称之为"C10k"问题,就是处理大于或等于一万的并发.一万呀,这可是不小的量 条件:处理器为 AMD Opteron, 主频 ...
- Python 简单聊天室
#coding=utf-8 from socket import * from threading import Thread import time udpSocket = socket(AF_IN ...
- Win7添加php环境变量.
1) "我的电脑"右键"属性"->高级系统设置->环境变量->系统变量->Path->编辑 2) 将PHP的执行路径的目录&quo ...
- SpringCloud的Archaius - 动态管理属性配置
参考链接:http://www.th7.cn/Program/java/201608/919853.shtml 一.Archaius是什么? Archaius用于动态管理属性配置文件. 参考自Gett ...