(中等) 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块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
随机推荐
- ABI & API
API defines the programning language and function entry point, arguments type, order. ABI defines th ...
- 天棋哥哥大战AlphaGo
天棋哥哥大战AlphaGo Time Limit: 1 Sec Memory Limit: 128 MB Submit: 20 Solved: 9 [Submit][Status][Web Boa ...
- java 随机流
Example10_8.java import java.io.*; public class Example10_8 { public static void main(String args[]) ...
- cocos2d-x 3.3 显示中文
Resources文件夹下的strings.xml: <dict> <key>targetScore</key> <string>目标分数</st ...
- 学习笔记——Windows下cocos2d-x,eclipse中自编译
cocos2d-x创建的安卓项目导入eclipse后. 在项目属性中配置Builders. 在eclipse编译还需要配置相应的变量,即后面提到的cygwin编译中要添加的变量. D:/cygdriv ...
- JVM CPU打满问题定位
1.线程不释放,导致Old区占满,系统不停的FullGC 发现应用并没有在进行FGC,而是进行频繁的YGC. YGC也存在异常,S1和S0区域都是从0直接跳到99% 观察堆大小装太发现Young区内存 ...
- Ubuntu和Redhat(Debian)的差别
这两个最大的区别在包管理模式上. 都是用的Linux核心构架的. Redhat主要集中在 企业级服务器版的制作 是推动LINUX商业化最成功的公司 Redhat对应的桌面版制作 都是由Fedora社区 ...
- Ubuntu 12.04 怎样安装 Google Chrome
方法一: http://www.360doc.com/content/14/0723/19/4338_396584130.shtml 方法2: How to Install Google Chrome ...
- js 中ajax请求时设置 http请求头中的x-requestd-with= ajax
今天发现 AngularJS 框架的$http服务提供的$http.get() /$http.post()的ajax请求中没有带 x-requested-with字段. 这样的话,后端的php 就无法 ...
- UIButton 解析
IOS之按钮控件--Button全解析及使用 转载自:forget IOS开发中伴随我们始终的 最常用的几个空间之一 -- UIButton 按钮,对于button今天在此做一些浅析,并介绍下主流用 ...