UVa1471
保留有价值的数字的做法,实际上这道题因为n只有1e5,所以不需要这种优化。
#include<bits/stdc++.h> #define inf 0x3f3f3f3f const int maxn=; using namespace std; int t; int n; struct node{
int val;
int dpl,dpr;
bool operator < (const node &rhs) const{
if(val == rhs.val)
return dpl < rhs.dpl;
else return val < rhs.val;
}
}a[maxn+]; set<node> s; void init(){
s.clear();
memset(a, , sizeof(a));
scanf("%d",&n);
for(int i = ; i <= n; ++i){
scanf("%d", &a[i].val);
}
for(int i = n; i >= ; --i){
if(a[i].val < a[i+].val){
a[i].dpr = a[i+].dpr + ;
} else{
a[i].dpr = ;
}
} } int solve(){
int res = ;
for(int i = ; i <= n; ++i){
if(a[i].val > a[i-].val){
a[i].dpl = a[i-].dpl + ;
} else {
a[i].dpl = ;
}
set<node>::iterator it1 = s.lower_bound(a[i]);
if(it1 != s.begin()){
--it1;
res = max(res, (*it1).dpl + a[i].dpr);
} else res = max(res, a[i].dpr);
if(i == ){
s.insert(a[i]);
continue;
}
set<node>::iterator it = s.lower_bound(a[i]);
set<node>::iterator temp = it;
if(it != s.begin()){
--it;
if((*it).dpl >= (a[i]).dpl){
continue;
}
}
it = temp;
while(it != s.end()){
if((*it).dpl <= a[i].dpl){
it = s.erase(it);
} else {
break;
}
}
s.insert(a[i]);
}
return res;
} int main()
{
scanf("%d",&t);
while(t--){
init();
int ans = solve();
printf("%d\n", ans);
}
return ;
}
UVa1471的更多相关文章
- UVA1471( LIS变形)
这是LIS的变形,题意是求一个序列中去掉某个连续的序列后,能得到的最长连续递增序列的长度. 用DP的解法是:吧这个序列用数组a来记录,再分别用两个数组f记录以i结尾的最长连续递增序列的长度,g[i]记 ...
- uva1471 二叉搜索树
此题紫书上面有详细分析,关键是运用Set优化实现O(nlgn)复杂度 AC代码: #include<cstdio> #include<set> #include<algo ...
- 8-8 Ddfense Line uva1471 优先级队列
题意:给你一串长度为n的序列 你的任务是删除一个连续的子序列 使得剩下的序列中有一个长度最大的连续递增子序列 例如 将 5 3 4 9 2 8 6 7 1 中的9 2 8 删除 得到5 3 ...
- 二分 连续上升子序列变形 UVA1471
最大上升子序列解法: 1.动规转移方程 2.(nlogn) #include<cstdio> #include<algorithm> using namespace std; ...
- UVa 1471 防线
https://vjudge.net/problem/UVA-1471 题意:给出一个序列,删除一个连续子序列,使得剩下的序列中有一个长度最大的连续递增子序列,输出个数. 思路:首先可以计算出以i结尾 ...
- 【二分】Defense Lines
[UVa1471] Defense Lines 算法入门经典第8章8-8 (P242) 题目大意:将一个序列删去一个连续子序列,问最长的严格上升子序列 (N<=200000) 试题分析:算法1: ...
随机推荐
- 引用 qsort与sort的比较
引用 linpder 的 qsort与sort的比较 在C/C++标准库中提供了快速排序的函数qsort():在STL中也提供了sort()排序函数,那么这两个函数哪个快呢?之前与代码-> ...
- SpringBoot_Exception_02_Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:run
一.现象 上一个异常解决之后,出现了这个异常: [WARNING] The requested profile "pom.xml" could not be activated b ...
- OpenCV——高斯模糊与毛玻璃特效
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- 解决系统存在大量TIME_WAIT状态的连接
系统存在大量TIME_WAIT状态的连接,通过调整内核参数解决, vi /etc/sysctl.conf 编辑文件,加入以下内容:net.ipv4.tcp_syncookies = 1net.ipv4 ...
- ACM学习历程——UVA127 "Accordian" Patience(栈, 链表)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- 【Lintcode】098.Sort List
题目: Sort a linked list in O(n log n) time using constant space complexity. Example Given 1->3-> ...
- x264源代码分析-转
相关说明: 1. 使用版本: x264-cvs-2004-05-11 2. 这次的分析基本上已经将代码中最难理解的部分做了阐释,对代码的主线也做了剖析,如果这个主线理解了,就容易设置 ...
- 洛谷 P5061 秘密任务 —— 二分图
题目:https://www.luogu.org/problemnew/show/P5061 首先,“配合默契”就是连边的意思: 但发现答案不好统计,因为有连边的两个点可以分在一组,也可以不分在一组: ...
- java 基础知识学习 JVM虚拟机参数配置
1) 设置-Xms.-Xmx相等: 2) 设置NewSize.MaxNewSize相等: 3) 设置Heap size, PermGen space: Tomcat 的配置示例:修改%TOMCAT_H ...
- CodeForces 484A Bits(水题)
A. Bits time limit per test 1 second memory limit per test 256 megabytes input standard input output ...