(中等) UESTC 360 Another LCIS ,线段树+区间更新。
Description:
For a sequence S1,S2,⋯,SN, and a pair of integers (i,j), if 1≤i≤j≤N and Si<Si+1<Si+2<⋯<Sj−1<Sj, then the sequence Si,Si+1,⋯,Sj is a CIS(Continuous Increasing Subsequence). The longest CIS of a sequence is called the LCIS (Longest Continuous Increasing Subsequence).
In this problem, we will give you a sequence first, and then some add operations and some query operations. An add operation adds a value to each member in a specified interval. For a query operation, you should output the length of the LCIS of a specified interval.
题目大意就是说求一段区间的最大上升子序列(注意这里的子序列必须是连续的。)
对线段树维护前缀最大上升子序列,后缀最大上升子序列,最大上升子序列,以及区间左端点的值,右端点的值。
这里要注意如果pushUP时,左子树前缀为其长度,那么父亲的前缀的长度应该为左的加右的,右子树同理。
代码如下:
#include<iostream>
#include<cstdio> #define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; struct state
{
int lef,rig,mid;
int x,y;
}; int N,Q;
state BIT[*];
int COL[*];
int num[]; void pushDown(int po)
{
if(COL[po])
{
COL[po*]+=COL[po];
COL[po*+]+=COL[po];
BIT[po*].x+=COL[po];
BIT[po*].y+=COL[po];
BIT[po*+].x+=COL[po];
BIT[po*+].y+=COL[po];
COL[po]=;
}
} void pushUP(int L,int R,int po)
{
BIT[po].mid=max(BIT[po*].mid,BIT[po*+].mid);
BIT[po].lef=BIT[po*].lef;
BIT[po].rig=BIT[po*+].rig;
BIT[po].x=BIT[po*].x;
BIT[po].y=BIT[po*+].y; int M=(L+R)/; if(BIT[po*].y<BIT[po*+].x)
{
BIT[po].mid=max(BIT[po].mid,BIT[po*].rig+BIT[po*+].lef); if(BIT[po*].lef==M-L+)
BIT[po].lef=M-L++BIT[po*+].lef;
if(BIT[po*+].rig==R-M)
BIT[po].rig=R-M+BIT[po*].rig;
}
} void build_tree(int L,int R,int po)
{
if(L==R)
{
BIT[po].lef=BIT[po].rig=BIT[po].mid=;
scanf("%d",&COL[po]);
BIT[po].x=BIT[po].y=COL[po];
return;
} int M=(L+R)/; COL[po]=; build_tree(lson);
build_tree(rson); pushUP(L,R,po);
} void update(int ul,int ur,int add,int L,int R,int po)
{
if(ul<=L&&ur>=R)
{
COL[po]+=add;
BIT[po].x+=add;
BIT[po].y+=add;
return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
update(ul,ur,add,lson);
if(ur>M)
update(ul,ur,add,rson); pushUP(L,R,po);
} int query(int ql,int qr,int L,int R,int po)
{
if(ql<=L&&qr>=R)
return BIT[po].mid; pushDown(po); int M=(L+R)/;
int maxn; if(ql>M)
return query(ql,qr,rson);
else if(qr<=M)
return query(ql,qr,lson);
else
{
maxn=max(query(ql,qr,lson),query(ql,qr,rson)); if(BIT[po*].y<BIT[po*+].x)
maxn=max(maxn,min(M-ql+,BIT[po*].rig)+min(qr-M,BIT[po*+].lef)); return maxn;
}
} int main()
{
int T;
char ch[];
int a,b,c;
cin>>T; for(int cas=;cas<=T;++cas)
{
printf("Case #%d:\n",cas); scanf("%d %d",&N,&Q); build_tree(,N,); for(int i=;i<=Q;++i)
{
scanf("%s",ch); if(ch[]=='q')
{
scanf("%d %d",&a,&b);
printf("%d\n",query(a,b,,N,));
}
else
{
scanf("%d %d %d",&a,&b,&c);
update(a,b,c,,N,);
}
}
} return ;
}
(中等) UESTC 360 Another LCIS ,线段树+区间更新。的更多相关文章
- LCIS线段树(区间更新)
首先线段树每一个节点包含:[b,e],lmax,rmax,max;其中lmax表示从左端点开始连续的最长的增序列长度,rmax表示从e端点开始向左连续的最长下降序列长度,max表示当前区间的连续递增的 ...
- HDU 3308 LCIS 线段树区间更新
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新
#1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
随机推荐
- iOS NSMutableArray添加NSInteger元素
NSMutableArray *array = [[NSMutableArray alloc] init]; NSInteger num = 7; NSNumber *number = [NSNumb ...
- Android实现播放GIF动画的强大ImageView
我个人是比较喜欢逛贴吧的,贴吧里总是会有很多搞笑的动态图片,经常看一看就会感觉欢乐很多,可以释放掉不少平时的压力.确实,比起一张单调的图片,动态图片明显更加的有意思.一般动态图片都是GIF格式的,浏览 ...
- mysql中的substr()函数
mysql中的substr()函数和hibernate的substr()参数都一样,就是含义有所不同. 用法: substr(string string,num start,num length); ...
- ZOJ 2872 Binary Partitions
先写一个完全背包,然后找规律,然后打表. #include<cstdio> #include<cstring> #include<cmath> #include&l ...
- Stem Cell 华人科学家
Jianping Fu 密歇根大学机械工程系生物医学工程专业 PhD, Massachusetts Institute of Technology, 2007MS, University of Cal ...
- angular实现select的ng-options
html <div ng-controller="ngSelect"> <select ng-model="vm.selectVal" ng- ...
- 看详细的tomcat报错信息
WEB-INF/classes目录下新建一个文件叫logging.properties handlers = org.apache.juli.FileHandler, java.util.loggin ...
- JSP内置对象--web安全性及config对象的使用 (了解即可)
tomcat服务器配置的时候,在虚拟目录中必须存在一个WEB-INF文件夹,但是访问的时候并不能发现这个文件夹.改成WEB-INFs就可以看到. 所以WEB-INF文件夹不轻易让用户看到,那么其安全性 ...
- JSP标签编程--简单标签
javax.servlet.jsp.tagext里的类SimpleTagSupport 使用SimpleTagSupport类一网打尽以往复杂的标签开发,直接使用doTag()方法 java文件: p ...
- IPoint Interface接口
Description A Point is a zero-dimensional object that represents a specific (X, Y) location in a the ...