保留有价值的数字的做法,实际上这道题因为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. CentOS7 网络管理工具nmcli

    今天帮别人调试虚拟机的网络问题(CentOS 7系统),习惯性直接改/etc/sysconfig/network-scripts/ifcfg-xxx配置文件,但是不知道为什么重启network后静态i ...

  2. T61

    你参加了这次科学讨论会,有什么体会?What have you learned from the symposium?那墙有点斜.The wall is a little out of the per ...

  3. oracle Instant Client install

    Installation See the Instant Client Home Page for more information. Installation of ZIP files: 1. Do ...

  4. MySQL_活动期间单笔订单最高的且满600元 判别是重激活客户还是10月注册客户_20161031

    将29号和30号两个需求放到一个表当中 首先都满足在10.29到31号之间单笔订单最高的且满600元 数据结构为一个用户一个订单ID 一行一行的 上面是第一个表 我们当做主表 a 第二个表 我们找注册 ...

  5. ACM学习历程—HDU2068 RPG的错排(组合数学)

    Description 今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁.RPG给他机会让他猜猜,第一次猜:R是公主,P是草儿 ...

  6. 【Lintcode】153.Combination Sum II

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  7. 【Lintcode】137.Clone Graph

    题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

  8. kkkk

    monkey -p com.alfl.www  -v -v -v  --throttle 50 --pct-touch 30 --pct-motion 15 --pct-nav 15 --pct-ma ...

  9. c# link 学习网站

    http://www.cnblogs.com/shanyou/p/4353433.html

  10. Oracle tns 协议

    下面是翻译国外的一篇博客,原文连接如下: https://thesprawl.org/research/oracle-tns-protocol/ 简介 TNS(Transparent Network ...