Bellovin

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 858    Accepted Submission(s): 395

Problem Description
Peter has a sequence a1,a2,...,an and he define a function on the sequence -- F(a1,a2,...,an)=(f1,f2,...,fn), where fi is the length of the longest increasing subsequence ending with ai.

Peter would like to find another sequence b1,b2,...,bn in such a manner that F(a1,a2,...,an) equals to F(b1,b2,...,bn). Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.

The sequence a1,a2,...,an is lexicographically smaller than sequence b1,b2,...,bn, if there is such number i from 1 to n, that ak=bk for 1≤k<i and ai<bi.

 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first contains an integer n (1≤n≤100000) -- the length of the sequence. The second line contains n integers a1,a2,...,an (1≤ai≤109).

 
Output
For each test case, output n integers b1,b2,...,bn (1≤bi≤109) denoting the lexicographically smallest sequence.
 
Sample Input
3
1
10
5
5 4 3 2 1
3
1 3 5
 
Sample Output
1
1 1 1 1 1
1 2 3
 
Source
 
题意:给一个序列,求出每个位置结尾的最长上升子序列;然后找一个字典序最小的这个函数值相同的子序列;
其实就是求每个位置结尾的最长上升子序列的长度组成的序列。
 
题解:固定尾部的最长上升子序列的长度nlgn处理
exm[j] 表示长度为j的的序列的最后一个值的大小
lower_bound的使用 返回第一个大于等于key的位置 确保严格的上升
这是为什么呢? 找到相同的值结尾的序列 长度却没有变 保证了严格上升
不同于最长不下降(使用upper_bound 跳过了相同的值 也就是长度增加了)。
理解
 
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int t;
int a[];
int ans[];
int n;
int main()
{
scanf("%d",&t);
{
for(int i=; i<=t; i++)
{
scanf("%d",&n);
scanf("%d",&a[]);
ans[]=;
int exm[];
int top=;
exm[]=a[];
for(int j=; j<n; j++)
{
scanf("%d",&a[j]); if(a[j]>exm[top])
{
top=top+;
exm[top]=a[j];
ans[j]=top;
}
else
{
int pos=lower_bound(exm,exm+top,a[j])-exm;
exm[pos]=a[j];
ans[j]=pos;
}
}
for(int j=; j<n; j++)
{
if(j==)
printf("%d",ans[j]);
else
printf(" %d",ans[j]);
}
printf("\n");
}
}
return ;
}

HDU 5748 最长上升子序列的长度nlogn(固定尾部)的更多相关文章

  1. hdu 1950 最长上升子序列(lis) nlogn算法【dp】

    这个博客说的已经很好了.http://blog.csdn.net/shuangde800/article/details/7474903 简单记录一下自己学的: 问题就是求一个数列最长上升子序列的长度 ...

  2. 【最长下降子序列的长度和个数】 poj 1952

    转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...

  3. HDU 1025(最长上升子序列)

    题意是要在两条平行线间连点,要在线不交叉的前提下尽可能多的连线,问最多能连多少条线. 现假定题中所给的是 9 组点,分别是:1—3,2—8,3—5,4—9,5—2,6—4,7—6,8—7,9—1,如图 ...

  4. HDU 1159 最长公共子序列(n*m)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. HDU-1257 最少拦截系统 贪心/DP 最长上升子序列的长度==最长不上升子序列的个数?

    题目链接:https://cn.vjudge.net/problem/HDU-1257 题意 中文题咯中文题咯 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然 ...

  6. 最长上升子序列(LIS)长度的O(nlogn)算法

    最长上升子序列(LIS)的典型变形,熟悉的n^2的动归会超时.LIS问题可以优化为nlogn的算法.定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元素 ...

  7. HDU 5773 最长上升子序列

    题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上 ...

  8. HDU 1159 最长公共子序列

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. 最长上升子序列(LIS)长度及其数量

    例题51Nod-1376,一个经典问题,给出一个序列问该序列的LIS以及LIS的数量. 这里我学习了两种解法,思路和代码都是参考这两位大佬的: https://www.cnblogs.com/reve ...

随机推荐

  1. CSS 奇技淫巧十八招

    http://www.tuicool.com/articles/VZneI3   開始覺得自己會寫 CSS 也算有一段時間了,常常遇到一些非常實用的技巧不斷地反覆使用,但是我個人覺得對初學者來說很難從 ...

  2. IT公司100题-5-查找最小的k个元素

    问题描述: 输入n 个整数,输出其中最小的k 个. 例如输入8, 7, 6, 5, 4, 3, 2, 1这8 个数字,则最小的3 个数字为3, 2, 1.   分析: 时间复杂度O(nlogn)方法: ...

  3. C++string的操作

    #include <iostream> using namespace std; int main() { //initilization string str("abc.ddd ...

  4. OpenLayers简单介绍以及简单实例

    OpenLayers是一个强大的JavaScript包,可以从它的官网免费下载.OpenLayers包含了很多强大的网页地图展示与操作功能,并且能够将不同源的图层展示在同一张地图中,支持各种第三方的地 ...

  5. SQL Server 语句整理

    1. 创建数据库 create database dbName 2. 删除数据库 drop database dbName 3. 备份sql server --- 创建 备份数据的 device US ...

  6. Android 禁用以及捕捉home键

    最近要做个小项目,其中有需要禁止home键的需求,一开始以为不可以,感觉得root一下才行,后来查了一下,发现还是不少朋友都实现了这个功能,现在也引用一下,供大家参考一下: 1. 在activity中 ...

  7. PHP time() 函数

    定义和用法 time() 函数返回当前时间的 Unix 时间戳. 语法 time(void) 参数 描述 void 可选. 说明 返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 ...

  8. 一点点webservice的小知识

    怕自己忘了记录下来好了 在web.config中要配置自己要调用的webservice的地址 在自己controller中获取web.config中配置的地址 SystemManager.Config ...

  9. Scheme vs Schema

    在计算机数据描述领域,Scheme由于原意为“主题”,“方案”,“构想”等,因此一般指比较明确的(具体的)“方案”.“体系”,例如一个术语词表.分类表等,而Schema通常翻译成“模式”,比较强调形式 ...

  10. SVG 2D入门5 - 颜色的表示

    SVG和canvas中是一样的,都是使用标准的HTML/CSS中的颜色表示方法,这些颜色都可以用于fill和stroke属性.基本有下面这些定义颜色的方式:1. 颜色名字: 直接使用颜色名字red, ...