hdu 5748(LIS) Bellovin
Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an. 定义F(a1,a2,...,an)=(f1,f2,...,fn)F(a_1,a_2,...,a_n)=(f_1,f_2,...,f_n)F(a1,a2,...,an)=(f1,f2,...,fn), 其中fif_ifi是以aia_iai结尾的最长上升子序列的长度. Peter想要找到另一个序列b1,b2,...,bnb_1,b_2,...,b_nb1,b2,...,bn使得F(a1,a2,...,an)F(a_1,a_2,...,a_n)F(a1,a2,...,an)和F(b1,b2,...,bn)F(b_1,b_2,...,b_n)F(b1,b2,...,bn)相同. 对于所有可行的正整数序列, Peter想要那个字典序最小的序列. 序列a1,a2,...,ana_1, a_2, ..., a_na1,a2,...,an比b1,b2,...,bnb_1, b_2, ..., b_nb1,b2,...,bn字典序小, 当且仅当存在一个正整数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_kak=bk并且ai<bia_i < b_iai<bi.
输入包含多组数据, 第一行包含一个整数TTT表示测试数据组数. 对于每组数据: 第一行包含一个整数nnn (1≤n≤100000)(1 \le n \le 100000)(1≤n≤100000)表示序列的长度. 第二行包含nnn个整数a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an (1≤ai≤109)(1 \le a_i \le 10^9)(1≤ai≤109).
对于每组数据, 输出nnn个整数b1,b2,...,bnb_1,b_2,...,b_nb1,b2,...,bn (1≤bi≤109)(1 \le b_i \le 10^9)(1≤bi≤109)表示那个字典序最小的序列.
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的更多相关文章
- hdu 5748(LIS)
Bellovin Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- hdu 5748 Bellovin【最长上升子序列】
题目链接:https://vjudge.net/contest/148584#problem/A 题目大意: 解题思路:题目要求为:输出与已知序列的每一个元素的f(i)(f(i)的定义如题)相同的字典 ...
- hdu 5748(求解最长上升子序列的两种O(nlogn)姿势)
Bellovin Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...
- Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- HDU 1950(LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1950 Bridging signals Time Limit: 5000/1000 MS (Java ...
- hdu 1087(LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 1025 lis 注意细节!!!【dp】
感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...
- HDU 5748 最长上升子序列的长度nlogn(固定尾部)
Bellovin Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
随机推荐
- .Net操作Excel
先去官网:http://npoi.codeplex.com/下载需要引入dll(可以选择.net2.0或者.net4.0的dll),然后在网站中添加引用. .Net导出代码: /// <summ ...
- angular+bootstrap+MVC 之二,模态窗
本例实现一个bootstrap的模态窗 1.HTML代码 <!doctype html> <!--suppress ALL --> <html ng-app=" ...
- [zz]The Royal Treatment
http://www.cgw.com/Publications/CGW/2012/Volume-35-Issue-4-June-July-2012/The-Royal-Treatment.aspx T ...
- 关于 try catch catch
catch 和 finally 一起使用的常见方式是:在 try 块中获取并使用资源,在 catch 块中处理异常情况,并在 finally 块中释放资源. public class abc { st ...
- coderforces719b
题目大意:给定一个字符串,这个字符串中只有“r”和"b"组成,每次操作只能交换两个字符的位置或者将一个字符由"r"变"b"(或由" ...
- Android学习笔记(四)
一个应用程序是有很多活动构成的,使用Intent在活动间移动. Intent分为显式和隐式两种: 1.显示Intent: 新建一个布局文件,命名为second_layout.xml,代码如下 < ...
- Bugtags 与其它产品的区别
如果您刚刚接触 Bugtags,可能心里会有这样的疑问,下面将介绍 Bugtags 与其它的一些产品的区别. Bugtags 不是做统计的 SDK 大家都会在 App 里集成用户数据统计的 SDK,但 ...
- mysql 数据库乱码解决
mysql 数据库乱码解决, 进入前加入 set names 'utf8' 即可.
- python之I/O多路复用
python IO多路复用 一.多路复用概念: 监听多个描述符(文件描述符(windows下暂不支持).网络描述符)的状态,如果描述符状态改变 则会被内核修改标志位,进而被进程获取进而进行 ...
- python类及其方法
python类及其方法 一.介绍 在 Python 中,面向对象编程主要有两个主题,就是类和类实例类与实例:类与实例相互关联着:类是对象的定义,而实例是"真正的实物",它存放了类中 ...