[CEOI2018]Global warming
[CEOI2018]Global warming
题目大意:
给定\(n(n\le2\times10^5)\),你可以将任意\(a_{l\sim r}(1\le l\le r\le n)\)每一个元素加上一个\(d(|d|\le x)\),求\(a\)的LIS长度。
思路:
不难发现区间加一个数是为了使得LIS中间一段比左边一段大,而右边一段本来就比中间的大,那么我们给右边一段同时加上也不会影响答案。因此我们可以给一个后缀加上\(x\)求LIS即可。
用两个树状数组分别维护,当前是否是已被增加过的后缀,前缀LIS的最大值。
时间复杂度\(\mathcal O(n\log n)\)。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=2e5+1;
int a[N],tmp[N*2];
class SegmentTree {
private:
int val[N*2];
int lowbit(const int &x) const {
return x&-x;
}
public:
void modify(int p,const int &x) {
for(;p<=tmp[0];p+=lowbit(p)) {
val[p]=std::max(val[p],x);
}
}
int query(int p) const {
int ret=0;
for(;p;p-=lowbit(p)) {
ret=std::max(ret,val[p]);
}
return ret;
}
};
SegmentTree t[2];
int main() {
const int n=getint(),x=getint();
for(register int i=1;i<=n;i++) {
tmp[i]=a[i]=getint();
tmp[n+i]=a[i]+x;
}
std::sort(&tmp[1],&tmp[n*2]+1);
tmp[0]=std::unique(&tmp[1],&tmp[n*2]+1)-&tmp[1];
for(register int i=1;i<=n;i++) {
const int pos1=std::lower_bound(&tmp[1],&tmp[tmp[0]]+1,a[i]+x)-tmp;
t[1].modify(pos1,t[0].query(pos1-1)+1);
t[1].modify(pos1,t[1].query(pos1-1)+1);
const int pos0=std::lower_bound(&tmp[1],&tmp[tmp[0]]+1,a[i])-tmp;
t[0].modify(pos0,t[0].query(pos0-1)+1);
}
printf("%d\n",t[1].query(tmp[0]));
return 0;
}
[CEOI2018]Global warming的更多相关文章
- BZOJ5442: [Ceoi2018]Global warming
BZOJ5442: [Ceoi2018]Global warming https://lydsy.com/JudgeOnline/problem.php?id=5442 分析: 等价于后缀加(前缀减也 ...
- BZOJ 5442: [Ceoi2018]Global warming
[l,r]+x不如[l,n]+x [l,r]-x不如(r,n)+x 所以等价于只有[l,n]+x 枚举断点树状数组合并 难度在于想到这个贪心 #include<cstdio> #inclu ...
- 10324 Global Warming dfs + 二分
时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: G++;GCC Description Global warming is a big prob ...
- 【BZOJ4149】[AMPPZ2014]Global Warming 单调栈+RMQ+二分
[BZOJ4149][AMPPZ2014]Global Warming Description 给定一个序列a[1],a[2],...,a[n].请从中选出一段连续子序列,使得该区间最小值唯一.最大值 ...
- bzoj4149: [AMPPZ2014]Global Warming
头都烂了怎么头疼啊 考虑先做出对于一个位置以它作为唯一最小值的最远区间,这个可以单调栈上二分搞出来 那么对于一个位置这个区间而言,一定是选择这个区间的最大数是作为最终的唯一最大数最优的 为什么呢?我们 ...
- Emergency(山东省第一届ACM省赛)
Emergency Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...
- Moscow Pre-Finals Workshop 2016. National Taiwan U Selection
A. As Easy As Possible 每个点往右贪心找最近的点,可以得到一棵树,然后倍增查询即可. 时间复杂度$O((n+m)\log n)$. #include <bits/stdc+ ...
- sentence patterns
第四部分 推理题 1.世界上每个角落的每个人都有立场,都有背景,都有推理性,能推理出一个人语言的真意,才成就了真正的推理能力: 2.换言之,如果你能通过一个人的说话推理出其身份职业,你的推理能 ...
- AMPPZ2014
[AMPPZ2014]The Lawyer 记录每天结束的最早的会议以及开始的最晚的会议即可. #include<cstdio> #define N 500010 int n,m,i,d, ...
随机推荐
- mybatis入门基础----高级映射(一对一,一对多,多对多)
阅读目录 一:订单商品数据模型 二.一对一查询 三.一对多查询 四.多对多查询 回到顶部 一:订单商品数据模型 1.数据库执行脚本 创建数据库表代码: CREATE TABLE items ( id ...
- LaTeX文章结构
%导言 %\documentclass{article} %ctexbook \documentclass{ctexbook} \title{\heiti 监督学习} % 黑体 \author{\ka ...
- [转载]Windows 8 VHD 概述与使用
http://www.cnblogs.com/tonycody/archive/2012/11/30/2796858.html
- [整理]IIS 6.0 下部署 Asp.net MVC Web Api 后 HTTP PUT and DELETE 请求失败
http://guodong.me/?p=1560 ASP.NET MVC 4 has a new feature called WebAPI which makes it much easier t ...
- HTML5 defer和async的区别
在HTML页面中插入Javascript的主要方法,就是使用<script>元素.这个元素由Netscape创造并在Netscape Navigator 2中首先实现.后来,这个元素就被加 ...
- python模块分析之hashlib加密(二)
前言 hashlib模块是py3.+用来对字符串进行hash加密的模块,核心算法是md5,明文与密文是一一对应不变的关系:用于注册.登录时用户名.密码等加密使用. 模块分析 hashlib模块有多种加 ...
- CRT/LCD/VGA Information and Timing【转】
转自:http://www.cnblogs.com/shangdawei/p/4760933.html 彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for ...
- arm GIC介绍之四【转】
转自:https://blog.csdn.net/sunsissy/article/details/73882718 GIC是ARM体系中重要的组件,在认识到GIC的组成和功能之后,了解到IRQ的大致 ...
- linux网络编程--Circular Buffer(Ring Buffer) 环形缓冲区的设计与实现【转】
转自:https://blog.csdn.net/yusiguyuan/article/details/18368095 1. 应用场景 网络编程中有这样一种场景:需要应用程序代码一边从TCP/IP协 ...
- find查找时排除目录及文件
查找根目录下大于500M的文件,排除/proc目录 find / ! -path "/proc/*" -type f -size +500M | sort -rh|xargs ls ...