HDU 5489 二分 LIS
Removed Interval
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1703 Accepted Submission(s): 558
, a subsequence b1,b2,…,bk
of A
is referred as increasing if b1<b2<…<bk
. LY has just learned how to find the longest increasing subsequence (LIS).
Now that he has to select L
consecutive numbers and remove them from A
for some mysterious reasons. He can choose arbitrary starting position of the selected interval so that the length of the LIS of the remaining numbers is maximized. Can you help him with this problem?
indicating the number of test cases (T≤100
).
For each test case, the first line consists of two numbers N
and L
as described above (1≤N≤100000,0≤L≤N
). The second line consists of N
integers indicating the sequence. The absolute value of the numbers is no greater than 109
.
The sum of N over all test cases will not exceed 500000.
is the test case number starting from 1. Y
is the maximum length of LIS after removing the interval.
5 2
1 2 3 4 5
5 3
5 4 3 2 1
Case #2: 1
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<set>
#define ll __int64
#define mod 100000000
#define N 5e6+10
#define M 1e
using namespace std;
int t;
int n,l;
int a[],b[];
int dp[];
int ans[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d %d",&n,&l);
a[]=;
for(int j=;j<=n;j++){
scanf("%d",&a[j]);
b[j]=-a[j];
}
int exm=;
ans[exm]=a[];
dp[]=;
for(int j=;j<=n;j++)
{
if(a[j]>ans[exm]){
exm++;
ans[exm]=a[j];
dp[j]=exm;
}
else
{
int pos=lower_bound(ans+,ans+exm,a[j])-ans;
ans[pos]=a[j];
dp[j]=pos;
}
}
int an=;
for(int j=;j<=n;j++)
ans[j]=1e9;
int re=;
for(int j=n-l;j>=;j--)
{
int x=lower_bound(ans,ans+n,b[j])-ans;//
an=max(an,dp[j]+x);
int y=lower_bound(ans,ans+n,b[j+l])-ans;
ans[y]=b[j+l];
re=max(re,y+);
}
printf("Case #%d: %d\n",i,max(an,re));
}
return ;
}
/*
6
6 2
1 3 5 7 2 4
*/
HDU 5489 二分 LIS的更多相关文章
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...
- hdu 4024 二分
转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html 一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...
- 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...
- HDU 5489 Removed Interval (LIS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...
- hdu 5489(LIS最长上升子序列)
题意:一个含有n个元素的数组,删去k个连续数后,最长上升子序列 /*思路参考GoZy 思路: 4 2 3 [5 7 8] 9 11 ,括号表示要删掉的数, 所以 最长上升子序列 = ...
- hdu 5489——Removed Interval——————【删除一段区间后的LIS】
Removed Interval Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5489 Removed Interval (LIS,变形)
题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...
- HDU 5489 Removed Interval 2015 ACM/ICPC Asia Regional Hefei Online (LIS变形)
定义f[i]表示以i为开头往后的最长上升子序列,d[i]表示以i为结尾的最长上升子序列. 先nlogn算出f[i], 从i-L开始枚举f[i],表示假设i在最终的LIS中,往[0,i-L)里找到满足a ...
- HDU - 3564 Another LIS(LIS+线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意 给出1~n的插入顺序,要求每次插入之后的LIS 分析 首先用线段树还原出最终序列.因为插入的顺序是按 ...
随机推荐
- 3星|《CMO到底能干多久?》:CEO必须决定供公司需要哪类CMO
CMO到底能干多久?(<哈佛商业评论>增刊) <哈佛商业评论>关于CMO的6篇文章.我认为第一篇<为何CMO宝座坐不长>写的最好,是典型的哈评风格:做过实际调查.有 ...
- 美国警察iPhone数据线挡住歹徒子弹获救
泡泡网手机频道11月1日 现在手机的功能越来越丰富,不仅可以接打电话.收发短信.玩游戏聊天,关键时刻还能救命.前天HTC手机再次忠心护主,让许多同学对HTC赞赏有加.而现在又有人捡了一条命,不过这次救 ...
- USACO 1.4.2 Mother's Mil 母亲的牛奶(DFS)
Description 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数,最初,A和B桶都是空的,而C桶是装满牛奶的.有时,约翰把牛奶从一个桶倒到另一个桶中,直到被灌桶装 ...
- Alpha发布——视频博客
1.视频链接 视频上传至优酷自频道,地址链接:https://v.youku.com/v_show/id_XMzg5MzQ4MzM2MA==.html?spm=a2h0k.11417342.sores ...
- 20181120-6 Beta阶段第2周/共2周 Scrum立会报告+燃尽图 03
此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制地址 [https://git.coding.n ...
- 按照Right-BICEP要求设计四则运算3程序的单元测试用例
按照Right-BICEP要求: Right——结果是否正确? B——是否所有的边界条件都是正确的? I——能查一下反响关联吗? C——能用其它手段交叉检查一下吗? E——你是否可以强制错误条件发生? ...
- 按照事务类型分析 DB2 事物的性能
概述 事务是数据库系统中的核心概念之一.作为数据库系统的逻辑工作单元(Unit of Work),事务必须具有四个属性,即原子性.一致性.隔离性和持久性(ACID).数据库系统往往通过锁机制保证事务的 ...
- CCF——折点计数201604-1
问题描述 给定n个整数表示一个商店连续n天的销售量.如果某天之前销售量在增长,而后一天销售量减少,则称这一天为折点,反过来如果之前销售量减少而后一天销售量增长,也称这一天为折点.其他的天都不是折点.如 ...
- memached实现tomcat的session共享
由于项目服务器用的阿里云的ECS,Memcached也采用的阿里云.多个tomcat集群的session都存储在一个云memcached中. 配置步骤如下: 一.tomcat增加memcached支持 ...
- Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错,
Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错, 这里总结一些可能的原因和解决方案,给需要的朋友: 说道undefined reference err ...