POJ3903Stock Exchange (LIS)
学了下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)的更多相关文章
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- 浅谈最长上升子序列(LIS)
一.瞎扯的内容 给一个长度为n的序列,求它的最长上升子序列(LIS) 简单的dp n=read(); ;i<=n;i++) a[i]=read(); ;i<=n;i++) ;j<i; ...
- 最长递增子序列(LIS)(转)
最长递增子序列(LIS) 本博文转自作者:Yx.Ac 文章来源:勇幸|Thinking (http://www.ahathinking.com) --- 最长递增子序列又叫做最长上升子序列 ...
- Poj 2533 Longest Ordered Subsequence(LIS)
一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- DP——最长上升子序列(LIS)
DP——最长上升子序列(LIS) 基本定义: 一个序列中最长的单调递增的子序列,字符子序列指的是字符串中不一定连续但先后顺序一致的n个字符,即可以去掉字符串中的部分字符,但不可改变其前后顺序. LIS ...
- 最长上升子序列(LIS)nlogn模板
参考https://www.cnblogs.com/yuelian/p/8745807.html 注意最长上升子序列用lower_bound,最长不下降子序列用upper_bound 比如123458 ...
- 低价购买 (动态规划,变种最长下降子序列(LIS))
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
- 最长上升子序列(LIS)问题
最长上升子序列(LIS)问题 此处我们只讨论严格单调递增的子序列求法. 前面O(n2)的算法我们省略掉,直接进入O(nlgn)算法. 方法一:dp + 树状数组 定义dp[i]:末尾数字是i时最长上升 ...
随机推荐
- 学习Linux须知1.2之Linux命令的实战
(一)学习Linux 的准备工作 1.在线学习linux 学习网站推荐:Linux 基础入门_Linux - 蓝桥云课 (lanqiao.cn) 2.连接远程服务器学习[下文的案例就是使用xshell ...
- 《Effective C++》阅读总结(四): 设计、声明与实现
第四章: 设计与声明 18. 让接口更容易被正确使用,不易被误用 将你的class的public接口设计的符合class所扮演的角色,必要时不仅对传参类型限制,还对传参的值域进一步限制. 19. 设计 ...
- 一分钟学会如何自定义小程序轮播图(蜜雪冰城Demo)
最近开发小程序项目用到了轮播图,默认的有点单调,作为后端程序员,研究一番最终实现了.本文会从思路,代码详细介绍,相信读过此文后,不管以后在开发中碰到轮播图还是需要自定义修改其他的样式都可以按这个思路解 ...
- vue跑马灯vue3-marquee
安装vue3-marquee 如果您使用的是 npm: npm install vue3-marquee@latest --save 如果您使用的是yarn: yarn add vue3-marque ...
- 验证cuda和cudnn是否安装成功(转载)
本人cuda安装目录: 当然cuda安装目录也可默认:此处为方便安装不同cuda版本,所以单独建了文件夹. 转载自:https://zhuanlan.zhihu.com/p/139668028 安装完 ...
- docker-compose 搭建 Prometheus+Grafana监控系统
有关监控选型之前有写过一篇文章: 监控系统选型,一文轻松搞定! 监控对象 Linux服务器 Docker Redis MySQL 数据采集 1).prometheus: 采集数据 2).node-ex ...
- springboot执行流程
构造方法初始化,创建一个新的实例,这个应用程序的上下文要从指定的来源加载bean public SpringApplication(ResourceLoaderresourceLoader,Class ...
- C语言学习之我见-strcat()字符拼接函数(有缺陷)
strcat()函数,用于两个字符串的拼接. (1)函数原型: char * strcat(char *Dest,const char * Source); (2)头文件: #include < ...
- Node.js精进(3)——流
在 JavaScript 中,一般只处理字符串层面的数据,但是在 Node.js 中,需要处理网络.文件等二进制数据. 由此,引入了Buffer和Stream的概念,两者都是字节层面的操作. Buff ...
- 数字图像处理-基于matlab-直方图均匀化,傅立叶变换,图像平滑,图像锐化
直方图均匀化 任务:用MATLAB或VC或Delphi等实现图像直方图均匀化的算法. clc;clear;close all; % 清除工作台 % path(path,'..\pics'); % 设置 ...