题目链接:https://vjudge.net/contest/148584#problem/A

题目大意:

解题思路:
题目要求为:输出与已知序列的每一个元素的f(i)(f(i)的定义如题)相同的字典序最小的序列。稍微思考便知,其实就是叫我们求出原序列的f(i),这个很容易做到,只要在最长上升子序列的模板题上稍微做一些改动,记录下原序列每一个元素的f(i)即可。具体实现见代码。

#include <bits/stdc++.h>
using namespace std; const int N = 1e5+;
int rise[N],ans[N];
int n; int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);
int len=;rise[]=-;
for(int i=;i<=n;i++){
int data;scanf("%d",&data);
if(data>rise[len])rise[++len]=data,ans[i]=len; //记录以i为末尾的最长上升子序列的长度
else {
int loc=lower_bound(rise+,rise++len,data)-rise; //最长上升子序列用lower_bound
rise[loc]=data;
ans[i]=loc; //记录以i为末尾的最长上升子序列的长度
}
}
for(int i=;i<=n;i++)
i==n?printf("%d\n",ans[i]):printf("%d ",ans[i]);
}
}

hdu 5748 Bellovin【最长上升子序列】的更多相关文章

  1. hdu 5748(求解最长上升子序列的两种O(nlogn)姿势)

    Bellovin Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...

  2. HDU 4681 String 最长公共子序列

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4681 题意: 给你a,b,c三个串,构造一个d串使得d是a,b的子序列,并且c是d的连续子串.求d最大 ...

  3. hdu 1025 dp 最长上升子序列

    //Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...

  4. div.2/Bellovin<最长上升子序列>

    题意: 序列arr[i--n];输出以a[i]为结尾的最长上升子序列.1<=n<=100000; 思路: O(n*log(n)),求最长上升子序列. #include<cstdio& ...

  5. hdu 5489(LIS最长上升子序列)

    题意:一个含有n个元素的数组,删去k个连续数后,最长上升子序列        /*思路参考GoZy 思路: 4 2 3 [5 7 8] 9 11 ,括号表示要删掉的数, 所以  最长上升子序列  = ...

  6. hdu 5532(最长上升子序列)

    Input The first line contains an integer T indicating the total number of test cases. Each test case ...

  7. HDU 1159.Common Subsequence-最长公共子序列(LCS)

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

  8. Bridging signals hdu 1950 (最长上升子序列)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=1950 题意:求最长上升(不连续or连续)子序列 推荐博客链接: http://blog.csdn.n ...

  9. HDU 4604 deque 最长上升子序列

    枚举每个位置,求以num[i]为起点的最长不下降子序列和以num[i]为结尾的最长不递增子序列. 并且把相同值的个数统计一下,最后要减去算重复了的. 比如: 1 9 4 4 2 2 2 3 3 3 7 ...

随机推荐

  1. MySQL Load Data InFile 数据导入数据库

    常用如下: Load Data InFile 'C:/Data.txt' Into Table `TableTest` Lines Terminated By '\r\n'; 这个语句,字段默认用制表 ...

  2. Python2和Python3中print的不同点

    在Python2和Python3中都提供print()方法来打印信息,但两个版本间的print稍微有差异 主要体现在以下几个方面: 1.python3中print是一个内置函数,有多个参数,而pyth ...

  3. 第一次安卓android studio安装,常见问题。

    出处:纸月 托了很久终于开始学习安卓了,之前看课本教程<第一行代码>用的是eclipse,但后来它不支持了就决定用android studio,第一次安装就出现了一些小的问题 第一个是关于 ...

  4. 【转】利用URLConnection来发送POST和GET请求

    URL的openConnection()方法将返回一个URLConnection对象,该对象表示应用程序和 URL 之间的通信链接.程序可以通过URLConnection实例向该URL发送请求.读取U ...

  5. Qt 窗体使用 label 标签插入静态图片

    最近在做毕业设计,上位机软件用的Qt,界面当中需要加入学校校徽,结果百度了n多种方法,有用QPixmap的: QPixmap myPix("./school.jpg"); ui-& ...

  6. ROS 多台计算机联网控制机器人

    0. 时间同步 sudo apt-get install chrony 1. ubuntu自带的有openssh-client 可以通过如下指令 ssh username@host 来连接同一局域网内 ...

  7. js的正则表达式编程,悬赏解决下面的问题

    悬赏解决下面的问题 1.切分url 2.将时间日期 转化为 yyyy-MM-dd的模式和可逆性 3.数据的千分位和可逆性 4.用C#或者nodejs检索如下的模式 h1{ border:1px sol ...

  8. MFC_CFileDialog_选择文件夹

    场景 在MFC中有时候只需要选择一个文件夹而不需要选择文件,这时候可以通过下列方式来进行选择 技术点 BROWSEINFO typedef struct_browseinfo { HWND hwndO ...

  9. Difference between plt.draw() and plt.show() in matplotlib

    Difference between plt.draw() and plt.show() in matplotlib down voteaccepted plt.show() will display ...

  10. 【Shell】带颜色输出(白底x色)

    echo -e "\033[31mHello World.\033[0m" 红色31m 绿色32m 黄色33m 蓝色34m 黑色30m 白色37m 紫色35m 深绿色36m