题目链接: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. POJ 1811 Prime Test (Rabin-Miller强伪素数测试 和Pollard-rho 因数分解)

    题目链接 Description Given a big integer number, you are required to find out whether it's a prime numbe ...

  2. python中的%s%是什么意思

    它是一个字符串格式化语法(它从C借用). 请参阅  “格式化字符串”: Python支持将值格式化为字符串.虽然这可以包括非常复杂的表达式,但最基本的用法是将值插入到%s 占位符的字符串中  . 编辑 ...

  3. oracle建包,函数demo

    create table BOOK ( BOOK_ID NUMBER(10), BOOK_NAME VARCHAR2(10) ); create or replace package chen_pac ...

  4. python3之Django多数据库

    1.定义数据库 在django项目中, 一个工程中存在多个APP应用很常见:有时候希望不同的APP连接不同的数据库,这个时候需要建立多个数据库连接.在Django的setting中使用DATABASE ...

  5. gpio_request 原形代码【转】

    转自:http://blog.csdn.net/maopig/article/details/7428561 其原型为 int gpio_request(unsigned gpio, const ch ...

  6. haproxy配置基于ssl证书的https负载均衡

    本实验全部在haproxy1.5.19版本进行测试通过,经过测试1.7.X及haproxy1.3版本以下haproxy配置参数可能不适用,需要注意版本号. 一.业务要求现在根据业务的实际需要,有以下几 ...

  7. 使用 IIS 在 Windows 上托管 ASP.NET Core

    参考微软文档: https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/index?tabs=aspnetcore2x 将as ...

  8. PhpStrom添加调试功能

    要给PhpStrom添加调试功能,需要安装Xdebug,网址:https://xdebug.org/ 1.如何下载对应thinkphp版本号的Xdebug呢 创建一个php文件,在里面输入phpinf ...

  9. selenium webdriver+python基本操作

    # -*- coding:utf-8 -*-#导入模块from selenium import webdriver from selenium.common.exceptions import NoS ...

  10. navicat连接sqlserver数据库提示:未发现数据源名称并且未指定默认驱动程序

    原因是navicat没有安装sqlserver驱动,就在navicat安装目录下,找到双击安装即可: