学了下BIT,炸了。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 100007; #define int long long
int n;
int a[N], b[N], f[N];
int t[N];
inline void Updata(int x, int val){
for(; x <= n; x += x & -x) t[x] = Max(t[x], val);
}
inline int Query(int x){
// int s = 2147483648;
int s = 0;
for(; x; x -= x & -x) s = Max(s, t[x]);
return s;
}
#undef int
int main(){
#define int long long
while(~scanf("%lld", &n)){
R(i,1,n){
io >> a[i];
// b[i] = a[i];
}
// sort(b + 1, b + n + 1);
// int len = unique(b + 1, b + n + 1) - b - 1;
// for(register int i = 1; i <= n; i += 3){
// t[i] = 0, t[i + 1] = 0, t[i + 2] = 0;
// }
// int ans = 0;
// R(i,1,n){
// int pos = upper_bound(b + 1, b + len + 1, a[i]) - b;
// f[i] = f[Query(pos)] + 1;
// Updata(pos, f[i]);
// ans = Max(ans, f[i]);
// }
// printf("%lld\n", ans);
int len = 1;
b[1] = a[1];
R(i,2,n){
if(a[i] > b[len]) b[++len] = a[i];
else{
*lower_bound(b + 1, b + len + 1, a[i]) = a[i];
}
}
printf("%lld\n", len);
} return 0;
}

HACK lower_bound 和 upper_bound 搞混のCode

10

3 9 8 3 5 7 9 6 4 5

POJ3903Stock Exchange (LIS)的更多相关文章

  1. Poj 3903 Stock Exchange(LIS)

    一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...

  2. ZOJ 1093 Monkey and Banana (LIS)解题报告

    ZOJ  1093   Monkey and Banana  (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  3. 浅谈最长上升子序列(LIS)

    一.瞎扯的内容 给一个长度为n的序列,求它的最长上升子序列(LIS) 简单的dp n=read(); ;i<=n;i++) a[i]=read(); ;i<=n;i++) ;j<i; ...

  4. 最长递增子序列(LIS)(转)

    最长递增子序列(LIS)   本博文转自作者:Yx.Ac   文章来源:勇幸|Thinking (http://www.ahathinking.com)   --- 最长递增子序列又叫做最长上升子序列 ...

  5. Poj 2533 Longest Ordered Subsequence(LIS)

    一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

  6. DP——最长上升子序列(LIS)

    DP——最长上升子序列(LIS) 基本定义: 一个序列中最长的单调递增的子序列,字符子序列指的是字符串中不一定连续但先后顺序一致的n个字符,即可以去掉字符串中的部分字符,但不可改变其前后顺序. LIS ...

  7. 最长上升子序列(LIS)nlogn模板

    参考https://www.cnblogs.com/yuelian/p/8745807.html 注意最长上升子序列用lower_bound,最长不下降子序列用upper_bound 比如123458 ...

  8. 低价购买 (动态规划,变种最长下降子序列(LIS))

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  9. 最长上升子序列(LIS)问题

    最长上升子序列(LIS)问题 此处我们只讨论严格单调递增的子序列求法. 前面O(n2)的算法我们省略掉,直接进入O(nlgn)算法. 方法一:dp + 树状数组 定义dp[i]:末尾数字是i时最长上升 ...

随机推荐

  1. vision transformer

    VIT 总览 Step1 Step2

  2. README.exe 是的,你看错是EXE

    SmartIDE让你的README变成可执行文档,再也不用编写无用的文档,再也不必操心环境问题.   作为开发者,拿到一个新的代码库的时候一般都会先去看README文件,通过这个文件可以知道这套代码所 ...

  3. [算法学习] 换根dp

    换根dp 一般来说,我们做题的树都是默认 \(1\) 为根的.但是有些题目需要计算以每个节点为根时的内容. 朴素的暴力:以每个点 \(u\) 作为 \(root\) 暴力dfs下去,复杂度\(O(n^ ...

  4. .net core 抛异常对性能影响的求证之路

    一.前言 在.net 社区中曾经听到过很多关于大量抛异常会影响性能这样的结论,心中一直就存在各种疑问.项目中使用自定义异常来处理业务很爽,但是又担心大量抛业务异常存在性能问题. 查阅了各种文档,微软官 ...

  5. VMware 虚拟机安装CentOS镜像详细步骤

    CentOS目前官网提供的下载版本有6.7.8,最新的版本为8,不过个人推荐CentOS 7 的版本,因为相比较于最新版本,版本7更加地稳定.而相比于版本6,版本7新增了很多的功能.CentOS 7 ...

  6. 『忘了再学』Shell流程控制 — 38、while循环和until循环介绍

    目录 1.while循环 2.until循环 1.while循环 对while循环来讲,只要条件判断式成立,循环就会一直继续,直到条件判断式不成立,循环才会停止.和for循环的第二种格式for((初始 ...

  7. SAP LUW 实现提交数据库更新

    CALL FUNCTION 'TRANSACTION_BEGIN' IMPORTING transaction_id = lv_transaction_id. * 更新日志表 MODIFY zfit0 ...

  8. 【python基础】第03回 软件安装

    上节内容回顾 1.计算机五大组成部分详解 1.控制器 控制计算机各个硬件的工作 2.运算器 数学运算.逻辑运算(核心) """CPU = 控制器 + 运算器"& ...

  9. 【python基础】第02回 计算机基础2

    上节内容回顾 1.绝对路径与相对路径 1.路径的概念 用来标识资源的位置 2.绝对路径 类似于全球GPS定位(给到任何人都可以顺利的找到相应的资源) eg: D:\aaa\a.txt 3.相对路径 需 ...

  10. sql-扩展sql

    复制表结构 create table 表名 like 被复制的表名; -- 仅复制表表结构 oracle不支持 复制表结构和数据(子查询方式) CREATE TABLE 表名 [AS] SELECT ...