依据问题转换成最长不降子序列问题。

10^9的输入数据计算起来还是挺花时间的。由于这里仅仅能使用O(nlgn)时间复杂度了。

只是证明是能够算出10^9个数据的。

由于时间限制是5s.

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std; const int MAX_N = 20;
vector<int> arr, a2;
int N; inline int lSon(int rt) { return rt<<1|1; }
inline int rSon(int rt) { return (rt<<1)+2; } void postOrder(int rt, int &v)
{
int l = lSon(rt), r = rSon(rt);
if (l < N) postOrder(l, v);
if (r < N) postOrder(r, ++v);
a2.push_back(arr[rt]-v);
} int biGetIndex(int low, int up, int v)
{
while (low <= up)
{
int mid = low + ((up-low)>>1);
if (v < a2[mid]) up = mid-1;
else low = mid+1;
}
return low;
} int LIS()
{
int j = 0;
for (int i = 1; i < N; i++)
{
if (a2[i] >= a2[j]) a2[++j] = a2[i];
else
{
int id = biGetIndex(0, j, a2[i]);
a2[id] = a2[i];
}
}
return j+1;
} int main()
{
int a;
scanf("%d", &N);
arr.clear(), a2.clear();
while (scanf("%d", &a) != EOF)
{
arr.push_back(a);
} N = (int) arr.size();
int v = 0;
postOrder(0, v);
int len = LIS();
printf("%d\n", N-len);
return 0;
}

Heap 3214 LIS题解的更多相关文章

  1. HDU4352 XHXJ's LIS 题解 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 题目大意: 求区间 \([L,R]\) 范围内最长上升子序列(Longest increasin ...

  2. BZOJ3173:[TJOI2013]最长上升子序列 & HDU3564:Another LIS——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3173 http://acm.hdu.edu.cn/showproblem.php?pid=3564 ...

  3. python数据结构之堆(heap)

    本篇学习内容为堆的性质.python实现插入与删除操作.堆复杂度表.python内置方法生成堆. 区分堆(heap)与栈(stack):堆与二叉树有关,像一堆金字塔型泥沙:而栈像一个直立垃圾桶,一列下 ...

  4. HDU 4352 XHXJ's LIS 数位dp lis

    目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...

  5. HDU5489 LIS变形

    Removed Interval Problem Description Given a sequence of numbers A=a1,a2,…,aN , a subsequence b1,b2, ...

  6. Shortest and Longest LIS

    Codeforces Round #620 (Div. 2) D. Shortest and Longest LIS 题解: 贪心即可,对于最短序列,我们尽可能用可用的最大数字放入序列中,对于最长序列 ...

  7. 2019HDU多校 Round6

    Solved:2 02 Nonsense Time (LIS) 题意:给定一个全排列 最开始为空的 每秒中一个位置上的数出现 求每秒的LIS 题解:题解说 考虑时光倒流 倒着消掉 因为数据随机 所以期 ...

  8. 【CF486E】LIS of Sequence题解

    [CF486E]LIS of Sequence题解 题目链接 题意: 给你一个长度为n的序列a1,a2,...,an,你需要把这n个元素分成三类:1,2,3: 1:所有的最长上升子序列都不包含这个元素 ...

  9. HDU 4352 XHXJ's LIS HDU 题解

    题目 #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the ent ...

随机推荐

  1. [bzoj1010](HNOI2008)玩具装箱toy(动态规划+斜率优化+单调队列)

    Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有 的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1.. ...

  2. BZOJ 4029: [HEOI2015]定价 贪心

    4029: [HEOI2015]定价 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4029 Description 在市场上有很多商品的 ...

  3. 通过OpenVPN来穿越上网(未实践)

    说明: 1.其实OpenVPN可以通过其实现穿越来上网,即全部请求都经过OpenVPN来处理.其原理是iptables转发.如果全程走iptables也是可以的,网上的教程基本都是基于iptables ...

  4. \r和\n的区别

    /n  是换行/r   是回车 这是两码事,换行是指移动到下一行,回车是指移动到行首,我们通常所说的“回车”其实是这两个动作的结合.

  5. Unity3d通用工具类之生成文件的MD5

    今天我们来写写工具类,这个类有什么用呢? 也就是无论你做什么项目,这个工具类你都可以拿来用,之所以通用,是可以适用所有项目. 这节我主要讲如何生成文件的MD5码. 那么这个MD5是个什么鬼东西,读者可 ...

  6. ylbtech-LanguageSamples-UserConversions(用户定义的转换)

    ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-UserConversions(用户定义的转换) 1.A,示例(Sample) 返回顶部 ...

  7. git 统计代码量 shell脚本

    #!/bin/bash # 统计代码量 # 使用方法: sh gitstat.sh "2017-11-01" "2017-11-30" "JamKon ...

  8. 各种语言性能(CPU密集型程序)比较

    都进行Fib数列计算,计算到n=40的计算时间: 注意:开始,我以为上图中的第二列就是代表C++的性能.但是现在发现,完全不正确. 如果你使用同样的抽象和同样的逻辑去实现同样的代码,C和C++的性能几 ...

  9. python matplotlib.pyplot学习记录

    matplotlib是python中很强大的绘图工具,在机器学习中经常用到 首先是导入 import matplotlib.pyplot as plt plt中有很多方法,记录下常用的方法 plt.p ...

  10. 关于Java的File类、字节流和字符流

    一.File类: 在Windows下的路径分隔符(\)和在Linux下的路径分隔符(/)是不一样的,当直接使用绝对路径时,跨平台会报No Such file or diretory异常. File中还 ...