以下参考自刘汝佳老师代码,使用了stl中的set,set集合不会插入的重复元素

#include<cstdio>
#include<set>
#include<cassert>
using namespace std;const int maxn = 200000 + 5;
int n, a[maxn], f[maxn], g[maxn];struct Candidate {int a, g;Candidate(int a, int g):a(a),g(g) {}bool operator < (const Candidate& rhs) const {return a < rhs.a;}
};set<Candidate> s;int main() {int T;scanf("%d", &T);while(T--) {scanf("%d", &n);for(int i = 0; i < n; i++)scanf("%d", &a[i]);if(n == 1) { printf("1\n"); continue; }// g[i] is the length of longest increasing continuous subsequence ending at ig[0] = 1;for(int i = 1; i < n; i++)if(a[i-1] < a[i]) g[i] = g[i-1] + 1;else g[i] = 1;// f[i] is the length of longest increasing continuous subsequence starting from if[n-1] = 1;for(int i = n-2; i >= 0; i--)if(a[i] < a[i+1]) f[i] = f[i+1] + 1;else f[i] = 1;s.clear();s.insert(Candidate(a[0], g[0]));int ans = 1;for(int i = 1; i < n; i++) {Candidate c(a[i], g[i]);set<Candidate>::iterator it = s.lower_bound(c); // first one that is >= cbool keep = true;if(it != s.begin()) {Candidate last = *(--it); // (--it) points to the largest one that is < cint len = f[i] + last.g; ans = max(ans, len);if(c.g <= last.g) keep = false;}if(keep) {//s.erase(c); // if c.a is already present, the old g must be <= c.gs.insert(c);it = s.find(c); // this is a bit cumbersome and slow but it's clearit++;while(it != s.end() && it->a > c.a && it->g <= c.g) s.erase(it++);}}printf("%d\n", ans);}return 0;
}

紫书 防线 UVa1471相关推荐

  1. UVa 1339,紫书P73,词频

    题目链接:https://uva.onlinejudge.org/external/13/1339.pdf 紫书P73 解题报告: #include <stdio.h> #include ...

  2. 11行代码AC——比紫书优化,例题2-3 近似计算——解题报告

    励志用更少的代码做高效的表达 题意: 计算π/4 = 1 - 1/3 + 1/5 - 1/7 + -,直到最后一项小于10^-6. 思路分析: 本题很简单,因此计算重心从解题转化为优化. 本题为重复计 ...

  3. 比紫书优化,14行代码AC——例题 5-7 丑数(Ugly Numbers,UVa 136)——解题报告

    题意: 丑数是一些因子只有2,3,5的数.数列1,2,3,4,5,6,8,9,10,12,15--写出了从小到大的前11个丑数,1属于丑数.现在请你编写程序,找出第1500个丑数是什么. 没有输入 输 ...

  4. 紫书 团队队列(队列)

    1.用两个队列来维护成员,一个队列维护队伍编号,一个队列数组维护每个队伍的成员 ps: 紫书p118 #include <bits/stdc++.h> using namespace st ...

  5. (紫书,感谢作者)第7章暴力求解法

    今天,我们谈一谈紫书上面的内容--暴力求解法 对于一道问题来说,我们是可以借助计算机运算快的特点,将所有可能的情况全部(不一定是全部)列出来,然后去寻找我们想要的答案,这就是暴力求解了,但暴力求解绝对 ...

  6. 【紫书】(UVa12096) The SetStack Computer

    突然转进到第五章的low题目的原因是做到图论了(紫书),然后惊喜的发现第一题就做不出来.那么里面用到了这一题的思想,我们就先解决这题.当然,dp必须继续做下去,这是基本功.断不得. 题意分析 这条题真 ...

  7. ACM入门攻略(紫书入门,不间断更新)

    声明:本文仅供参考,并且假定读者已经可以熟练运用C语言及其相关知识(大神请走开,谢谢配合). 目录:一.ACM入门的相关准备(书籍,OJ,编程语言,常用网站或工具)            二.入门阶段 ...

  8. 【紫书】第一章实验+问题

    紫书第1章实验 实验A1:表达式11111∗1111111111\ast1111111111∗11111的值是多少?改成6个1呢?9个1呢? 以下几个都用有符号整数%d\%d%d输出结果. 表达式11 ...

  9. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

最新文章

  1. Spock测试框架中的注解使用
  2. python趣味编程10例-Python趣味编程与精彩实例
  3. 2012-02-25工作记录
  4. 315汽车大型排雷现场,数据总结避雷规律
  5. Python笔记-使用U2自动登录某APP及watcher使用
  6. Python编程 | 新手必会的 9 个 Python 技巧
  7. python sql逐行读取数据库数据,使用python读取数据库中的内容 把爬虫爬到的内容,存储在mysql数据库中...
  8. 操作系统第二章总结/
  9. C++中string的用法
  10. LeetCode Binary Tree PostorderTranversal
  11. pyqt5多线程使用方法及学习案例(QThread)
  12. HashTable、ConcurrentHashMap、TreeMap、HashMap关于键值的区别
  13. 多国电子书盈利模式分析
  14. Android手账本案例
  15. 初中计算机期末质量分析,信息技术期末质量分析
  16. 盘点国内外那些形式多样的能量采集技术
  17. 如何解决“MSCOMCTL.ocx を読み込めません” 即 MSCOMCTL.ocx加载失败?
  18. Html Table 合并单元格
  19. VSCode系列之IDEA快捷键
  20. 广告程序万能搜索(无能搜索)WNSO.exe

热门文章

  1. mysql子查询中不能使用LIMIT
  2. 【CodeForces 1263C --- Everyone is a Winner!】
  3. puppet的web管理工具foreman安装配置简明步骤
  4. MoveWindow and SetWindowPos
  5. Linux反弹shell方式总结
  6. python按顺序批量修改文件名
  7. 打印机共享出现操作无法完成(错误0x00000709)【转自微信公众号网管爱好者】
  8. 如何防止电脑被远程控制(简单易懂)
  9. 使用启动U盘安装Ubuntu系统全过程(含图文)
  10. [论文笔记]Face X-ray for More General Face Forgery Detection