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

Peter would like to find another sequence b1,b2,...,bnb1,b2,...,bn

in such a manner that F(a1,a2,...,an)F(a1,a2,...,an)

equals to F(b1,b2,...,bn)F(b1,b2,...,bn)

. Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.

The sequence a1,a2,...,ana1,a2,...,an

is lexicographically smaller than sequence b1,b2,...,bnb1,b2,...,bn

, if there is such number ii

from 11

to nn

, that ak=bkak=bk

for 1≤k<i1≤k<i

and ai<biai<bi

.InputThere are multiple test cases. The first line of input contains an integer TT

, indicating the number of test cases. For each test case:

The first contains an integer nn

(1≤n≤100000)(1≤n≤100000)

-- the length of the sequence. The second line contains nn

integers a1,a2,...,ana1,a2,...,an

(1≤ai≤109)(1≤ai≤109)

.OutputFor each test case, output nn

integers b1,b2,...,bnb1,b2,...,bn

(1≤bi≤109)(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

题意:

就是求fi,即求以ai为最后一位的最长子序列

解法:

扫描这一个数组a,每一个数进入dp数组,在里面找到<=a[i]的下标最小的指针,在这里面存储a[i]。

lower_bound(dp,dp+n,a[i])-dp+1   这个是找到>=a[i]的最小指针减去dp数组的首指针再加1

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#define inf 0x3f3f3f
using namespace std;
typedef long long ll;
ll a[110000],dp[110000]; int main()
{
int t;
cin>>t;
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%I64d",&a[i]);
memset(dp,inf,sizeof(dp));
for(int i=0;i<n-1;i++)
{
*lower_bound(dp,dp+n,a[i])=a[i];
printf("%d ",lower_bound(dp,dp+n,a[i])-dp+1);
}
*lower_bound(dp,dp+n,a[n-1])=a[n-1];
printf("%d\n",lower_bound(dp,dp+n,a[n-1])-dp+1);
}
return 0;
}

  

美人鱼 hdu 5784的更多相关文章

  1. HDU 5784 (计算几何)

    Problem How Many Triangles (HDU 5784) 题目大意 给定平面上的n个点(n<2000),询问可以组成多少个锐角三角形. 解题分析 直接统计锐角三角形较困难,考虑 ...

  2. hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形

    How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...

  3. HDU 5784 How Many Triangles

    计算几何,极角排序,双指针,二分. 直接找锐角三角形的个数不好找,可以通过反面来求解. 首先,$n$个点最多能组成三角形个数有$C_n^3$个,但是这之中还包括了直角三角形,钝角三角形,平角三角形,我 ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. 第4章 Selenium2-java WebDriver API (三)

    4.12  上传文件  4.12.1  sendKeys实现上传  html <html> <head> </head> <body> <div ...

  2. Asp.Net MVC +EntityFramework主从表新增编辑操作的实现(删除操作怎么实现?)

    Asp.Net MVC +EntityFramework主从表新增编辑操作的实现 对于MVC中同时对主从表的表单操作在网上现有的解决很少,而这样的操作在做业务系统中是经常为遇到的.我在网上搜索了很久都 ...

  3. #5 Python变量与输入输出

    前言 学习一门编程语言,最基本的无非不过学习其变量规则.条件语句.循环语句和函数,接下来的几节将开始记录这些基本的语法,本节主要记录变量规则! 一.Python输入输出 在说Python变量之前,先补 ...

  4. Django组件之Middleware

    一.中间件 在django的settings.py文件下,有一个变量为MIDDLEWARE,里面放的就是中间件. MIDDLEWARE = [ 'django.middleware.security. ...

  5. PowerDesigner V16.5 安装教程以及汉化(数据库建模)

    一.power designer是什么以及是干什么的? power designer是能进行数据库设计的强大的软件,是一款开发人员常用的数据库建模工具.分别从概念数据模型(Conceptual Dat ...

  6. url字符长度限制解决办法

    前段时间,同事往系统上传相关文档,发现输入失败,找到了我了. 开始以为数据库字段属性问题,修改后未解决随调试系统,发现没有走到后台程序,发现 ajax没有传值,各种测试问题情况,后来同事发现是url字 ...

  7. jQuery性能优化的一些参考建议

    JQ3.1 文档下载地址:https://pan.baidu.com/s/1c2vMQdy 一.注意定义jQuery变量的时候添加var关键字 这个不仅仅是JQ,在JS中都是必须的 二.如果有多个变量 ...

  8. 集合类--最详细的面试宝典--看这篇就够用了(java 1.8)

    看了一个星期源码,搜索上百篇博文,终于总结出了集合类的所有基础知识点,学集合,看这篇就够用了!!! 篇幅有点长, 如果你能全部理解,java最重要的集合就不怕了,秒过面试!!!(本篇素材来自网络,如有 ...

  9. 关于input的焦点事件

    关于input的焦点事件 $(".scanf_integral").focus(function(){//获取焦点//获取焦点后触发的事件 }) $(".scanf_in ...

  10. Gradle自动实现Android组件化模块构建

    背景 随着App的不断迭代,业务会变得越来越复杂,业务模块会越来越多,且每个模块的代码也会变得越来越多.为了应对这一场景,我们需要把不同的业务模块划分成一个个组件,在修改业务代码的时候只需要在对应模块 ...