CSUOJ 1551 Longest Increasing Subsequence Again
1551: Longest Increasing Subsequence Again
Time Limit: 2 Sec Memory Limit: 256 MB
Submit: 75 Solved: 52
Description
Give you a numeric sequence. If you can demolish arbitrary amount of numbers, what is the length of the longest increasing sequence, which is made up of consecutive numbers? It sounds like Longest Increasing Subsequence at first sight. So, there is another limitation: the numbers you deleted must be consecutive.
Input
There are several test cases.
For each test case, the first line of input contains the length of sequence N(1≤N≤10^4). The second line contains the elements of sequence——N positive integers not larger than 10^4.
Output
For each the case, output one integer per line, denoting the length of the longest increasing sequence of consecutive numbers, which is achievable by demolishing some(may be zero) consecutive numbers.
Sample Input
7
1 7 3 5 9 4 8
6
2 3 100 4 4 5
Sample Output
4
4
HINT
Source
解题:线段树。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct node{
int lt,rt,value;
}tree[maxn<<];
struct Block {
int lt,rt;
} block[maxn];
void build(int lt,int rt,int v) {
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].value = ;
if(lt == rt) return;
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
}
int query(int id,int v) {
if(tree[v].lt == tree[v].rt) return ;
int mid = (tree[v].lt + tree[v].rt)>>;
if(id <= mid) return max(query(id,v<<),tree[v<<|].value);
return query(id,v<<|);
}
void update(int id,int v,int value) {
int mid = (tree[v].lt + tree[v].rt)>>;
tree[v].value = max(tree[v].value,value);
if(tree[v].lt == tree[v].rt) return;
if(id <= mid) update(id,v<<,value);
else update(id,v<<|,value);
}
int n,m,d[maxn],discrete[maxn],width[maxn];
int main() {
while(~scanf("%d",&n)) {
for(int i = m = ; i < n; ++i) {
scanf("%d",d+i);
discrete[i] = d[i];
}
sort(discrete,discrete+n);
int len = unique(discrete,discrete+n) - discrete;
build(,len-,);
block[m].lt = block[m].rt = ;
for(int i = ; i < n; ++i)
if(d[i-] < d[i]) block[m].rt++;
else {
++m;
block[m].lt = block[m].rt=i;
}
for(int i = ; i <= m; ++i)
for(int j = block[i].rt; j >= block[i].lt; --j)
width[j] = block[i].rt-j+;
int ans = ;
for(int i = m; i >= ; --i) {
for(int j = block[i].rt; j >= block[i].lt; --j) {
int id = lower_bound(discrete,discrete+len,d[j])-discrete;
ans = max(j - block[i].lt + + query(id,),ans);
update(id,,width[j]);
}
}
printf("%d\n",ans);
}
return ;
}
CSUOJ 1551 Longest Increasing Subsequence Again的更多相关文章
- CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...
- CSU 1551 Longest Increasing Subsequence Again(树状数组 或者 LIS变形)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 升级版:Uva 1471 题意: 让你求删除一段连续的子序列之后的LIS. 题 ...
- csu 1551: Longest Increasing Subsequence Again BIT + 思维
预处理last[i]表示以第i个开始,的合法后缀. pre[i]表示以第i个结尾,的合法前缀. 那么每一个数a[i],肯定是一个合法后缀last[i] + 一个合法前缀,那么合法前缀的数字要小于a[i ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [tem]Longest Increasing Subsequence(LIS)
Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- Leetcode 300 Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [LeetCode] Longest Increasing Subsequence
Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...
- The Longest Increasing Subsequence (LIS)
传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...
随机推荐
- input range 模拟滑块
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- js变量作用域和闭包的示例
<script> /* js是函数级作用域,在函数内部的变量,内部都能访问, 外部不能访问内部的,但是内部可以访问外部的变量 闭包就是拿到本不该属于他的东西,闭包会造成内存泄漏,你不知道什 ...
- 提高realm存储速率
我的数据量大约有2.5M,但是完全存储到数据库差不多用了11秒,有没有比较好的方法提高存储效率 提高realm存储速率 >> android这个答案描述的挺清楚的:http://www.g ...
- Cordova Android项目如何做代码混淆
我想修改build.gradle配置 可是这个文件明确写了// GENERATED FILE! DO NOT EDIT!可是还是试了试: if (cdvReleaseSigningProperties ...
- UWP开发小结
做了两天的UWP开发,上手还是挺快的,不过比较郁闷的是总会被一些很简单的细节卡住很久. 首先当然是用C#修改xaml界面这个难点了,Bing搜了好久都没找到相关信息,最后还是老司机伟神指点的我.对于g ...
- Hadoop集群配置搭建
环境:Centos 6.9,Hadoop 2.7.1,JDK 1.8.0_161,Maven 3.3.9 前言: 1.配置一台master服务器,两台或多台slave服务器. 2.master可 ...
- gitHub上如何设置或者取消电子邮箱提醒
原文链接:点我 我们正常注册的gitHub一般应该都是电子邮箱的方式,在注册账号时可能选择或者默认给了各种提醒,但是gitHub的邮箱提醒真的就比较烦人了,特别是最近团队开发项目,什么动态都有提醒,就 ...
- cygwin下调用make出现的奇怪现象
<lenovo@root 11:48:03> /cygdrive/d/liuhang/GitHub/rpi_linux/linux$make help 1 [main] make 4472 ...
- 到2023年将会有超过90%的PC采用SSD硬盘
本文转载自超能网,其他媒体转载需经超能网同意 现在买电脑或者自己装机,还有谁不要SSD硬盘吗?这个问题似乎没什么可说的,SSD硬盘各种好,装机可以说是必选了,但实际上现在的SSD适配率并没有想象中那么 ...
- HTML学习----------DAY1 第三节
本章通过实例向您演示最常用的 HTML 标签. 提示:不要担心本章中您还没有学过的例子,您将在下面的章节中学到它们. 提示:学习 HTML 最好的方式就是边学边做实验.我们为您准备了很好的 HTML ...