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的算 ...
随机推荐
- Android蓝牙串口程序开发
本文主要介绍了针对android的蓝牙串口上位机开发. 程序下载地址:点击打开链接 一.帧定义 androidclient依照一定的数据帧格式通过蓝牙串口发送数据到连接到MCU的蓝牙从机.MCU接收到 ...
- Okio简化处理I/O操作原理
转载:http://blog.csdn.net/sbsujjbcy/article/details/50523623 Okio库是一个由square公司开发的,它补充了java.io和java.nio ...
- 虚拟化技术对照:Xen vs KVM
恒天云:http://www.hengtianyun.com/download-show-id-68.html 一.说明 本文主要从功能方面和性能方面对Xen和KVM对照分析,分析出其优缺点指导我们恒 ...
- 判断QString是否为纯数字,查找自身最长重复子字符串
1.判断QString是否为纯数字 bool IsDigitString(QString strSource) { bool bDigit = false; if (strSource.isEmpty ...
- HD-ACM算法专攻系列(5)——N!
题目描述: 源码: #include"iostream" using namespace std; int main() { int n, digit, carry, tmp; i ...
- Creating a New Master Page in SharePoint 2013
Creating a New Master Page in SharePoint 2013 This article explains how to create a Master Page in S ...
- Activity-数据状态的保存
由于手机是便捷式移动设备,掌握在用户的手中,它的展示方向我们是无法预知的,具有不确定性.平时我们拿着手机多数为竖屏,但有时候我们感觉累了也会躺着去使用手机,那么这时手机屏幕的展示方向可能已经被用户切换 ...
- 「JavaSE 重新出发」02.02 引用数据类型
引用(复合)数据类型 1. 枚举类型 例: 枚举类型 Size 的声明: enum Size { SMALL, MEDIUM, LARGE, EXTRA_LARGE }; 声明 Size 类型变量: ...
- POJ 1182 食物链 【并查集】
解题思路:首先是没有思路的----然后看了几篇解题报告 http://blog.csdn.net/ditian1027/article/details/20804911 http://poj.org/ ...
- Sublimi Text3 下Emmet使用技巧
Emmet真的好用,可以少写很多代码. 初始化文档 HTML文档需要包含一些固定的标签,比如<html>.<head>.<body>等,现在你只需要1秒钟就可以输入 ...