hdu 5748

Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na​1​​,a​2​​,...,a​n​​. 定义F(a1,a2,...,an)=(f1,f2,...,fn)F(a_1,a_2,...,a_n)=(f_1,f_2,...,f_n)F(a​1​​,a​2​​,...,a​n​​)=(f​1​​,f​2​​,...,f​n​​), 其中fif_if​i​​是以aia_ia​i​​结尾的最长上升子序列的长度.

Peter想要找到另一个序列b1,b2,...,bnb_1,b_2,...,b_nb​1​​,b​2​​,...,b​n​​使得F(a1,a2,...,an)F(a_1,a_2,...,a_n)F(a​1​​,a​2​​,...,a​n​​)和F(b1,b2,...,bn)F(b_1,b_2,...,b_n)F(b​1​​,b​2​​,...,b​n​​)相同. 对于所有可行的正整数序列, Peter想要那个字典序最小的序列.

序列a1,a2,...,ana_1, a_2, ..., a_na​1​​,a​2​​,...,a​n​​比b1,b2,...,bnb_1, b_2, ..., b_nb​1​​,b​2​​,...,b​n​​字典序小, 当且仅当存在一个正整数iii (1≤i≤n)(1 \le i \le n)(1≤i≤n)满足对于所有的kkk (1≤k<i)(1 \le k < i)(1≤k<i)都有ak=bka_k = b_ka​k​​=b​k​​并且ai<bia_i < b_ia​i​​<b​i​​.
输入描述
输入包含多组数据, 第一行包含一个整数TTT表示测试数据组数. 对于每组数据:

第一行包含一个整数nnn (1≤n≤100000)(1 \le n \le 100000)(1≤n≤100000)表示序列的长度. 第二行包含nnn个整数a1,a2,...,ana_1,a_2,...,a_na​1​​,a​2​​,...,a​n​​ (1≤ai≤109)(1 \le a_i \le 10^9)(1≤a​i​​≤10​9​​).
输出描述
对于每组数据, 输出nnn个整数b1,b2,...,bnb_1,b_2,...,b_nb​1​​,b​2​​,...,b​n​​ (1≤bi≤109)(1 \le b_i \le 10^9)(1≤b​i​​≤10​9​​)表示那个字典序最小的序列.
输入样例
3
1
10
5
5 4 3 2 1
3
1 3 5
输出样例
1
1 1 1 1 1
1 2 3 就是一个nlgn的求最长上升子序列,比赛的时候脑抽了写了半天线段树
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int M = 1e5 + ;
int a[M],b[M],c[M],cas; int judge(int x)
{
int l=,r=cas,ans=;
while (l<=r)
{
int mid=(l+r)/;
if (c[mid]>x) r=mid-,ans=mid;
else if (c[mid]<x) l=mid+;
else return mid;
}
return ans;
} int main()
{
int t,n;
scanf("%d",&t);
while (t--){
scanf("%d",&n);
for (int i= ; i<=n ; i++) scanf("%d",&a[i]);
c[]=a[];b[]=;cas=;
for (int i= ; i<=n ; i++){
if (a[i]<c[]) c[]=a[i],b[i]=;
else if (a[i]>c[cas]) c[++cas]=a[i],b[i]=cas;
else { b[i]=judge(a[i]);c[b[i]]=a[i];}
}
for (int i= ; i<n ; i++)
printf("%d ",b[i]);
printf("%d\n",b[n]);
} return ;
}
												

hdu 5748(LIS) Bellovin的更多相关文章

  1. hdu 5748(LIS)

    Bellovin Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  2. hdu 5748 Bellovin【最长上升子序列】

    题目链接:https://vjudge.net/contest/148584#problem/A 题目大意: 解题思路:题目要求为:输出与已知序列的每一个元素的f(i)(f(i)的定义如题)相同的字典 ...

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

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

  4. Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. HDU 1025 LIS二分优化

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...

  6. HDU 1950(LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1950 Bridging signals Time Limit: 5000/1000 MS (Java ...

  7. hdu 1087(LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. hdu 1025 lis 注意细节!!!【dp】

    感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...

  9. HDU 5748 最长上升子序列的长度nlogn(固定尾部)

    Bellovin Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

随机推荐

  1. oracle返回多个参数

    CREATE OR REPLACE PACKAGE BODY get_form_no_pub IS /*================================================ ...

  2. WCF: 没有终结点在侦听可以接受消息的 这通常是由于不正确的地址或者 SOAP 操作导致的。

    问题:     由于我这里的wcf服务是采用“BasicHttpBinding”的方式,即安全绑定模式,客户端在引用这个服务后所生成的终结点配置(endpoint )就变成了<endpoint ...

  3. plsql登录找不到可连接数据库

    环境: OS:server 2008r2 64位 现象: plsql安装完成后,登录时数据库下拉列表为空,但主目录和oci库都能正常检测到. 原因: 系统环境变量未设置. 解决: 设置系统环境变量.t ...

  4. linux 安装软件程序

    1.用aptitude管理软件包 查看已安装的/未安装的等软件包 无法通过aptitude看到一个细节是所有跟某个特定软件包关联的所有文件的列表.利用dpkg命令能看到这个列表. dpkg -L pa ...

  5. powerDesigner 报Unable to connect SQLState=08004 解决方法

    在使用PowerDesigner配置数据库连接(configure connections)的时候,点击Test connection之后弹出Unable to connect SQLState=08 ...

  6. Chapter6: question 43 - 45

    43.  投 n 个骰子,计算点数和出现的概率 递归求解:(空间 O(5*n+1),时间 O(6n)) void count(int N, int curN, int sum, int record[ ...

  7. FPGA Verilog HDL 系列实例--------步进电机驱动控制

    [连载] FPGA Verilog HDL 系列实例 Verilog HDL 之 步进电机驱动控制 步进电机的用途还是非常广泛的,目前打印机,绘图仪,机器人等等设备都以步进电机为动力核心.那么,下面我 ...

  8. UVa10806 Dijkstra,Dijkstra-费用网络流

    Problem, in short Given a weighed, undirected graph, find the shortest path from S to T and back wit ...

  9. jdbc中c3p0的配置信息

    <c3p0-config> <!-- 这是默认配置信息 --> <default-config> <!-- 连接四大参数配置 --> <prope ...

  10. JavaScript实现类的private、protected、public、static以及继承

    JavaScript中的类 JavaScript实际上是一种弱类型语言,与C++和Java等语言不同.因此,在JavaScript中,没有强调类(class)这一概念,但实际运用中,类还是很重要的,比 ...