保留有价值的数字的做法,实际上这道题因为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的更多相关文章

  1. UVA1471( LIS变形)

    这是LIS的变形,题意是求一个序列中去掉某个连续的序列后,能得到的最长连续递增序列的长度. 用DP的解法是:吧这个序列用数组a来记录,再分别用两个数组f记录以i结尾的最长连续递增序列的长度,g[i]记 ...

  2. uva1471 二叉搜索树

    此题紫书上面有详细分析,关键是运用Set优化实现O(nlgn)复杂度 AC代码: #include<cstdio> #include<set> #include<algo ...

  3. 8-8 Ddfense Line uva1471 优先级队列

    题意:给你一串长度为n的序列   你的任务是删除一个连续的子序列  使得剩下的序列中有一个长度最大的连续递增子序列  例如  将 5 3 4 9 2 8 6 7 1 中的9 2 8 删除  得到5 3 ...

  4. 二分 连续上升子序列变形 UVA1471

    最大上升子序列解法: 1.动规转移方程 2.(nlogn) #include<cstdio> #include<algorithm> using namespace std; ...

  5. UVa 1471 防线

    https://vjudge.net/problem/UVA-1471 题意:给出一个序列,删除一个连续子序列,使得剩下的序列中有一个长度最大的连续递增子序列,输出个数. 思路:首先可以计算出以i结尾 ...

  6. 【二分】Defense Lines

    [UVa1471] Defense Lines 算法入门经典第8章8-8 (P242) 题目大意:将一个序列删去一个连续子序列,问最长的严格上升子序列 (N<=200000) 试题分析:算法1: ...

随机推荐

  1. 清除float浮动三种方式

    Float的作用? w3c的官方解释: Content flows down the right side of a left-floated box and down the left side o ...

  2. hls协议(最清晰的讲解)

    今天来介绍一下HLS协议,这个协议是由苹果公司提出并推广开来的.来一段维基百科的定义. HTTP Live Streaming(缩写是HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议.是 ...

  3. vim 模式下的几个快捷用法

    1.ctrl + v  (-- VISUAL BLOCK --) 选中块模式,y 复制,d 剪切,p 粘贴,Esc退出模式 2.Shift + v  (-- VISUAL LINE -- ) 快速行选 ...

  4. MySQL三个列组成唯一值查询_开源中国问题练习_20161026

    问题地址:https://www.oschina.net/question/2923955_2202674 按 service_collect_day分类以后,按 app_id,node_id,ser ...

  5. Vmware ESXi 6.5 安装手册

    1          安装前准备 1.1          硬件环境准备 无 备注: 本指导书以虚拟光驱.虚拟软驱为例,如使用物理光驱.物理软驱安装系统操作则以实际系统光盘.软盘代替. 1.2     ...

  6. Python之常用模块(一)

      time & datatime 模块 random os sys shutil json & picle   time & datetime 时间戳(1970年1月1日之后 ...

  7. u-boot.lds 链接脚本分析(hi3515)

    目录:/u-boot_hi3515/board/hi3515v100 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm& ...

  8. windows下搭建nginx服务器及实现nginx支持https配置流程

    最近刚接触到了tomcat结合nginx做网站的负载均衡.之前对tomcat搭配nginx实现负载均衡也写过,在上一篇的博客中,最近遇到的问题是要在http的基础上支持https.也就是支持加密的请求 ...

  9. 性能测试之Jmeter学习(八)

    本节主要学习:断言 JMeter也有像LR中的检查点,本节就来介绍下JMeter的检查点如何去实现. JMeter里面的检查点通过添加断言来完成. 检查点:上一节讲到,我们对用户名和密码进行了参数化, ...

  10. hdu 4123 Bob’s Race (dfs树上最远距离+RMQ)

    C - Bob’s Race Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Subm ...