HDU 5489 Removed Interval

题意:

求序列中切掉连续的L长度后的最长上升序列

思路:

从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值,在i~n中找到第一个比a[i - L]大的位置k,用LIS[i - L] + LDS[k]更新答案.

代码

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define eps 1e-8
#define INF 0x3f3f3f3f
#define LL long long
#define MAXN 500005
#define sqr(x) (x) * (x)
using namespace std;
int n, m, s;
int a[MAXN], b[MAXN], c[MAXN];
int f[MAXN], g[MAXN]; int LIS(int n){
int i, k;
k = 1;
c[1] = b[n];
g[n] = 1;
for (i = n - 1; i >= 1; i--){
if (b[i] > c[k]){
c[++k] = b[i];
g[i] = k;
}
else{
int pos = lower_bound(c + 1, c + k + 1, b[i]) - c;
c[pos] = b[i];
g[i] = pos;
}
}
return k;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int T;
scanf("%d", &T);
int cas = 1;
int n, L;
while (T--){
if (cas == 5){
cas = 5;
}
scanf("%d%d", &n, &L);
for (int i = 1; i <= n; i++){
scanf("%d", &a[i]);
b[i] = -a[i];
}
LIS(n);
int ans = 0;
int q = 0;
memset(f, INF, sizeof(f));
for (int i = L + 1; i <= n; i++){
int p = lower_bound(f + 1, f + n + 1, a[i]) - f;
ans = max(ans, p + g[i] - 1);
p = lower_bound(f + 1, f + n + 1, a[i - L]) - f;
f[p] = a[i - L];
q = max(q, p);
}
ans = max(ans, q);
printf("Case #%d: %d\n", cas++, ans);
}
}

2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)的更多相关文章

  1. 2015合肥网络赛 HDU 5492 Find a path 动归

    HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...

  2. HDU 5489 Removed Interval (LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...

  3. 2015上海网络赛 HDU 5475 An easy problem 线段树

    题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. #include<iostream> #include<cstdio> #include<cstr ...

  4. hdu 5489——Removed Interval——————【删除一段区间后的LIS】

    Removed Interval Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...

  6. 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 ...

  7. 2015上海网络赛 HDU 5478 Can you find it 数学

    HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...

  8. HDU 5489 Removed Interval

    题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...

  9. HDU 5489 Removed Interval (LIS,变形)

    题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...

随机推荐

  1. IntelliJ IDEA启动spring boot项目出现Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]

    IntelliJ IDEA启动spring boot项目出现Failed to start component [StandardEngine[Tomcat].StandardHost[localho ...

  2. java mail邮件发送(带附件) 支持SSL

    java mail邮件发送(带附件)有三个类 MailSenderInfo.java package mail; import java.util.Properties; import java.ut ...

  3. poj 2488 A Knight&#39;s Journey(dfs+字典序路径输出)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=2488 ----- ...

  4. 斯坦福新深度学习系统 NoScope:视频对象检测快1000倍

    以作备份,来源http://jiasuhui.com/archives/178954 本文由“新智元”(微信ID:AI_era)编译,来源:dawn.cs.stanford.edu,编译:刘小芹 斯坦 ...

  5. FireEye APT检测——APT业务占比过重,缺乏其他安全系统的查杀和修复功能

    摘自:https://zhidao.baidu.com/question/1694626564301467468.html火眼,APT威胁下快速成长 FireEye的兴起开始于2012年,这时段正好迎 ...

  6. [jzoj 5178] [NOIP2017提高组模拟6.28] So many prefix? 解题报告(KMP+DP)

    题目链接: https://jzoj.net/senior/#main/show/5178 题目: 题解: 我们定义$f[pos]$表示以位置pos为后缀的字符串对答案的贡献,答案就是$\sum_{i ...

  7. 解决局域网内无法IP访问IIS已发布的网站

    在IIS上发布的网站,本地可以访问,但是局域网内其他电脑却访问不了,原来是防火墙的问题,关闭它就可以访问了. 上面是我的简单操作 后来又百度了一下,发现有个更详细的操作:http://jingyan. ...

  8. ActiveMQ学习笔记(21)----ActiveMQ集成Tomcat

    1. 监控和管理Broker Web Console 方式:直接访问ActiveMQ的管理页面:http://localhost:8161/admin,默认的用户名和密码是admin/admin.具体 ...

  9. vue v-if的使用

    代码部分 <el-row> <el-col :span="20"> <template v-for="(node,i) of hierarc ...

  10. json对象获取长度以及字符串和json对象的转换

    var arr = Object.keys(typeARR); var str = ''; var len = arr.length; for(var i = 0;i<len;i++){ str ...