题目链接: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. Oracle设置某张表为只读

    Oracle 11g开始支持设置某张表为只读,这样可以防范对某些表的修改,起到一定的安全性. 设置如下: --设置表为只读权限(加锁) ALTER TABLE tab_name READ ONLY ; ...

  2. 关于Linux 虚拟机如何才能ping 通外网

    需要虚拟机能够联网.以前都是用桥接模式让虚拟机跟主机通信,这几天查了好多资料,都没有写得很详细,自己捣鼓了很久,把步骤写下来吧. 虚拟机操作步骤: 点击虚拟机的“菜单栏”上的“编辑”,再点击“虚拟网络 ...

  3. Python2和Python3中print的不同点

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

  4. python基础知识~配置文件模块

    一 配置文件模块   import ConfigParser ->导入模块  conf = ConfigParser.ConfigParser() ->初始化类二 系统函数  conf.r ...

  5. android aysncTask面试解析

  6. linux中fork()函数详解【转】

    转自:http://blog.csdn.net/jason314/article/details/5640969 一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过 ...

  7. gdb revert, Go to previous line in gdb

    Yes! With the new version 7.0 gdb, you can do exactly that! The command would be "reverse-step& ...

  8. vmware添加磁盘后linux无需重启识别的方法

    cd /sys/class/scsi_host/ [root@centos4 scsi_host]# ls host0 host1 host2 有几个host就刷几次 [root@centos4 sc ...

  9. WCF错误远程服务器返回了意外响应: (413) Request Entity Too Large。解决方案

    这个问题出现的原因是  调用wcf服务的时候传递的参数 长度太大   wcf数据传输采用的默认的大小是65535字节. ---------------------------------------- ...

  10. Day6-------------ext4文件系统

    1.cp /etc/passwd /sdb6 把/etc/passwd的内容写入 sdb6 写入过程:日志------------>刷到硬盘 2.ext4已经有点过时 xfs:可存海量数据 bt ...