题目链接:传送门

题目大意:给你n个数,m个操作。操作有两种:1.U x y 将数组第x位变为y   2. Q x y 问数组第x位到第y位连续最长子序列的长度。对于每次询问,输出一个答案

题目思路:线段树单点修改区间合并

     这道题题目好在对pushup的理解,我们在向上更新的时候有注意情况的区分

     1.如果左区间的最右边的值小于右区间最左边的值,则有一个待定答案是左儿子的右区间+右儿子的左区间

     2.如果不符合第一个条件,则有一个待定答案是左区间最大值和右区间最大值中较大的那一个。

     有一点要特别注意:如果当前区间中所有的值都符合上升序列,那么更新它的父节点时,它可以加上其他区间的边界值而进行扩充

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 100005
#define maxn 50005
typedef pair<int,int> PII;
typedef long long LL;
const double pi=acos(-1.0);
const double e=2.718281828459; int n,m,k,x,y;
int no[N<<],ls[N<<],rs[N<<];
int a[N];
inline void pushup(int rt,int l,int r){
int mid=l+r>>;
ls[rt]=ls[rt<<];rs[rt]=rs[rt<<|];
no[rt]=max(no[rt<<],no[rt<<|]);
if(a[mid]<a[mid+]){
if(ls[rt]==mid-l+)ls[rt]+=ls[rt<<|];
if(rs[rt]==r-mid)rs[rt]+=rs[rt<<];
no[rt]=max(no[rt],ls[rt<<|]+rs[rt<<]);
}
}
void build(int rt,int l,int r){
if(l==r){
no[rt]=ls[rt]=rs[rt]=;
return;
}
int mid=l+r>>;
build(lson);build(rson);
pushup(rt,l,r);
}
void add(int rt,int l,int r){
if(l==r){return;}
int mid=l+r>>;
if(x<=mid)add(lson);
else add(rson);
pushup(rt,l,r);
}
int query(int rt,int l,int r){
if(x<=l&&r<=y)return no[rt];
int mid=l+r>>;
if(y<=mid)return query(lson);
if(x>mid)return query(rson);
int t1=query(lson);
int t2=query(rson);
int ans=max(t1,t2);
if(a[mid]<a[mid+]){
ans=max(ans,(min(ls[rt<<|],y-mid)+min(rs[rt<<],mid+-x)));
}
return ans;
}
int main(){
int i,j,group;
scanf("%d",&group);
while(group--){
char str[];
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)scanf("%d",&a[i]);
build(,,n);
while(m--){
scanf("%s%d%d",str,&x,&y);
++x;
if(str[]=='U'){a[x]=y;add(,,n);}
else{++y;printf("%d\n",query(,,n));}
}
}
return ;
}

HDU3308(LCIS) 线段树好题的更多相关文章

  1. hdu-3308 LCIS (线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  3. POJ 3468 线段树裸题

    这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了A ...

  4. hdu-1540线段树刷题

    title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...

  5. hdu-5023线段树刷题

    title: hdu-5023线段树刷题 date: 2018-10-18 13:32:13 tags: acm 刷题 categories: ACM-线段树 概述 这道题和上次做的那道染色问题一样, ...

  6. poj-2777线段树刷题

    title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...

  7. zoj-1610线段树刷题

    title: zoj-1610线段树刷题 date: 2018-10-16 16:49:47 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道简单的线段树区间染色问 ...

  8. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题

    http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...

  9. hdu 1754 I Hate It 线段树基础题

    Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...

随机推荐

  1. Unix 网络编程 dup和dup2函数

    dup和dup2也是两个很实用的调用,它们的作用都是用来复制一个文件的描写叙述符. 它们经经常使用来重定向进程的stdin.stdout和stderr.这两个函数的原形例如以下: #include & ...

  2. 使用Python SDK管理Azure Load Balancer

    概述 下面将演示如何使用Python SDK管理中国区Azure Load balancer.关于Azure负载均衡器的详细功能介绍,请参考官方文档. Code Sample import os fr ...

  3. hbase 批量插入api

    1.数据格式a.txt: 1363157985066 13726230503 00-FD-07-A4-72-B8:CMCC 120.196.100.82 i02.c.aliimg.com 24 27 ...

  4. 12v继电器驱动电路

  5. 基于AngularJs + Bootstrap + AngularStrap 省市区联动实践

    什么是 AngularJs?网上一大堆资料,没能真正说明白. AngularJs 就是一个函数库,算不上一个框架,源码2万2千多行,提供了前端MVC的开发方式, 有双向绑定,指令等特性,这是具有革命性 ...

  6. Java并发编程(三):并发模拟(工具和Java代码介绍)

    并发模拟工具介绍 ① Postman : Http请求模拟工具 从图上我们可以看出,Postman模拟并发其实是分两步进行操作的.第一步:左边的窗口,在窗口中设置相关接口以及参数,点击运行进行第二步. ...

  7. 将HG版本库推送到Git服务器

    如何将HG版本库推送到Git服务器? 目的 习惯使用HG来进行版本管理,但是GitHub代码统计比Bitbucket要丰富,所以准备主力仓库选用Bitbucket,GitHub作为备用仓库. GitH ...

  8. Atitit.执行cli cmd的原理与调试

    Atitit.执行cli cmd的原理与调试 1. /c  与/k1 2. /k  参数,有利于调试1 3. -------code2 4. 打开程序后与openner脱离关系3 5. 返回参数 St ...

  9. PyCharm Python迁移项目

    把整个项目文件迁移过去后,执行文件会报不能执行XX,系统找不到指定的文件. 此时把当前的这个文件名字改一下,再运行,修改提示的错误.等错误全部修改,可以正常运行后,再把文件名改回去

  10. tail 命令详解

    tail 指令 功能:从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不 ...