保留有价值的数字的做法,实际上这道题因为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. RQNOJ 311 [NOIP2000]乘积最大:划分型dp

    题目链接:https://www.rqnoj.cn/problem/311 题意: 给你一个长度为n的数字,用t个乘号分开,问你分开后乘积最大为多少.(6<=n<=40,1<=k&l ...

  2. inode、软连接、硬链接

    一.inode是什么? 理解inode,要从文件储存说起.文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"(Sector).每个扇区储存512字节(相当于0.5KB).操作系统读取 ...

  3. codeforces 659A A. Round House(水题)

    题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. 集训Day11

    别人的题公开原题面不好 写题解吧 T1 很明显答案满足二分,二分之后算出每个人的位置,做一个LIS即可 T2 阅读体验极差 T3 根本不会 交都没交 期望得分200

  5. ACM学习历程—HDU2222 Keywords Search(字典树)

    Keywords Search Description In the modern time, Search engine came into the life of everybody like G ...

  6. bzoj 3230 相似子串 —— 后缀数组+二分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3230 先算出每个后缀贡献子串的区间: 然后前缀LCP直接查询,后缀LCP二分长度,查询即可: ...

  7. win32 UNICODE 支持

    #include <string> #ifdef _UNICODE #define tstring std::wstring #define __T(quote) L##quote #el ...

  8. python mysqldb 教程

    MySQL Python 教程 (1)下面是在Python中使用MySql数据库的教程,涵盖了Python对MySql的基础操作,主要采用了MySQLdb模块,下面的代码都是基于Ubuntu Linu ...

  9. go http 下载视频(TS码流文件)(推荐一个网站学习 go example)

    视频  http下载代码 dn.go(注意:代码很ugly,没怎么花时间) 总体感觉特别简单,网上看了下 net/http ,io这2个库的使用, 几分钟就写完了,感觉cpp 在做工具这块 开发效率的 ...

  10. fragment getActivity()空指针

    Fragment弹出toast,时不时出现getActivity()空指针,具体原因未查到. 解决办法: if (null == fragment || !fragment.isAdded()) { ...