hdoj5748 Bellovin 【BestCoder Round #84】 (最长上升序列)
来源:互联网 发布:python 矩阵运算 编辑:程序博客网 时间:2024/05/04 22:04
Problem Description
Peter has a sequence a1,a2,...,an and he define a function on the sequence -- F(a1,a2,...,an)=(f1,f2,...,fn) , where fi is the length of the longest increasing subsequence ending with ai .
Peter would like to find another sequenceb1,b2,...,bn in such a manner that F(a1,a2,...,an) equals to F(b1,b2,...,bn) . Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.
The sequencea1,a2,...,an is lexicographically smaller than sequence b1,b2,...,bn , if there is such number i from 1 to n , that ak=bk for 1≤k<i and ai<bi .
Peter would like to find another sequence
The sequence
Input
There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:
The first contains an integern (1≤n≤100000) -- the length of the sequence. The second line contains n integers a1,a2,...,an (1≤ai≤109) .
The first contains an integer
Output
For each test case, output n integers b1,b2,...,bn (1≤bi≤109) denoting the lexicographically smallest sequence.
Sample Input
311055 4 3 2 131 3 5
Sample Output
11 1 1 1 11 2 3
给你一个含有n个数的序列,a1,a2,a3.......,an.f[ i ]表示以a(i)结尾的序列的最长上升子序列的长度,依次输出.
代码如下:
#include<cstdio>#include<cstring>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int dp[100100];int a[100100];int f[100100];int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);int i ;for(i=0;i<n;i++){scanf("%d",&a[i]);}fill(dp,dp+n,INF);//注意这里初始化不能用memset for(i=0;i<n;i++){*lower_bound(dp,dp+n,a[i])=a[i];//将a[i]插入到第一个大于等于a[i]的位置 f[i]=lower_bound(dp,dp+n,a[i])-dp+1;//因为数组是从0开始的,所以结果要+1 }for(i=0;i<n-1;i++)printf("%d ",f[i]);printf("%d\n",f[n-1]);} }
0 0
- hdoj5748 Bellovin 【BestCoder Round #84】 (最长上升序列)
- 【HDU5748 BestCoder Round 84B】【LIS模板 最长单调上升子序列】Bellovin 以尾端点最长LIS压缩数组
- BestCoder Round #84 1002 hdu 5748 最长上升子序列
- BestCoder Round #84 Bellovin
- hdu 5748 Bellovin(BestCoder Round #84——最长递增子序列)
- BestCoder Round #84 1002 Bellovin
- Bellovin(最长上升子序列)
- div.2/Bellovin<最长上升子序列>
- HDU5748-Bellovin(最长上升子序列)
- hdoj 5748 Bellovin (LIS) 【BestCoder Round #84 】
- HDU 5748 Bellovin(最长上升子序列[nlogn])
- HDU5748-Bellovin【最长上升子序列的变形】
- Hdu5748-Bellovin-最长上升子序列(LIS)
- HDU 5748 BestCoder Round #84 Bellovin (LIS)(树状数组)
- hdu 5748 Bellovin BestCoder #84 1002
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- Android studio 删除所有注释
- 【NOIP2012模拟11.8】斐波那契
- 几个小问题。
- 【HDU 3072】【JZOJ 4686】 通讯
- 在不使用{}时,else执行到哪里结束
- hdoj5748 Bellovin 【BestCoder Round #84】 (最长上升序列)
- 关于遍历ArrayList中的梗
- bzoj 3110 K大数查询(树套树)
- android ViewPager的使用
- hdu 5829Rikka with Subset (2016多校第八场1009) FFT
- POJ 2112 Optimal Milking
- shell 定时执行任务
- const的用法
- 玩脫了的最小生成樹