2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
题意:
求序列中切掉连续的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+线段树(树状数组)的更多相关文章
- 2015合肥网络赛 HDU 5492 Find a path 动归
HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...
- HDU 5489 Removed Interval (LIS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...
- 2015上海网络赛 HDU 5475 An easy problem 线段树
题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. #include<iostream> #include<cstdio> #include<cstr ...
- 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 (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...
- 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 ...
- 2015上海网络赛 HDU 5478 Can you find it 数学
HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...
- HDU 5489 Removed Interval
题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...
- HDU 5489 Removed Interval (LIS,变形)
题意: 给出一个n个元素的序列,要求从中删除任一段长度为L的连续子序列,问删除后的LIS是多少?(n<=10w, L<=n ,元素可能为负) 思路: 如果会O(nlogn)求普通LIS的算 ...
随机推荐
- 轻松学习JavaScript十七:JavaScript的BOM学习(二)
JavaScript计时事件 通过使用JavaScript中的BOM对象中的window对象的两个方法就是setTimeout()方法和claerTimeout()方法,我们 有能力作到在一个设定的时 ...
- 怎样用批处理来执行多个exe文件
怎样用批处理来运行多个exe文件 @echo off start *****.exe start *****.exe start *****.exe start *****.exe 接着我们就能够运行 ...
- 关闭 sftp
vi /etc/ssh/sshd_config 注释掉这行Subsystem sftp /usr/libexec/openssh/sftp-server /etc/rc.d/init.d/ss ...
- JavaSE入门学习24:Java面向对象补充
一Java中的Object类 Object类是全部Java类的父类.假设一个类没有使用extendskeyword明白标识继承另外一个类,那么这个类默认 继承Object类. public class ...
- javaScript常用知识点有哪些
javaScript常用知识点有哪些 一.总结 一句话总结:int = ~~myVar, // to integer | 是二进制或, x|0 永远等于x:^为异或,同0异1,所以 x^0 还是永远等 ...
- 创建表空间及plsql查看远程表空间路径
-新建表空间,登录名和密码 --请尽量把表空间和别的系统分离,这里以Search为例子,登录名和密码以test为例子 create tablespace Search logging datafile ...
- Wireshark filter语法
过滤器语法 ------------------------------------------------------------- 最简单的过滤允许你检查一个协议或者字段的存在.如果你想查看所有的 ...
- Android TextView加下划线的几种方式
如果是在资源文件里: <resources> <</u></string> <string name="app_name">M ...
- 【原创】关于JMS[1]
面向消息中间件(MOM)为分布式系统提供异步,解耦,稳定,可扩展和安全的行为.MOM在分布式计算领域是一个重要的概念.它允许应用使用代理器API在分布式环境实现各种功能.Java消息服务(Java M ...
- 基于 Token 的身份验证:JSON Web Token
最近了解下基于 Token 的身份验证,跟大伙分享下.很多大型网站也都在用,比如 Facebook,Twitter,Google+,Github 等等,比起传统的身份验证方法,Token 扩展性更强, ...