题意: 有两种操作  一种是单点改为b  一种是给出区间ab  区间ab的最大上升子序列个数。。

线段树目前学了三种  第一种单点操作很简单   第二种区域操作加上懒惰标记即可

现在这种 为区间合并。。。。多看就好了

#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define lson L,m,pos<<1
#define rson m+1,R,pos<<1|1
#define mid m=(L+R)>>1
#define LL long long
int lsum[N<<],rsum[N<<],ssum[N<<],num[N]; void up(int L,int R,int pos)
{
int mid;
lsum[pos]=lsum[pos<<];
rsum[pos]=rsum[pos<<|];
ssum[pos]=max(ssum[pos<<],ssum[pos<<|]);//向上
if(num[m]<num[m+])
{
if(lsum[pos]==(m-L+))lsum[pos]+=lsum[pos<<|];
if(rsum[pos]==(R-m))rsum[pos]+=rsum[pos<<];
ssum[pos]=max(ssum[pos],lsum[pos<<|]+rsum[pos<<] );
}
} void build(int L,int R,int pos)
{
if(L==R)
{
scanf("%d",&num[L]);
lsum[pos]=rsum[pos]=ssum[pos]=;
return ;
}
int mid;
build(lson);
build(rson);
up(L,R,pos);
} void update(int x,int v,int L,int R,int pos)
{
if(L==R)
{
num[L]=v;
return;
}
int mid;
if(x<=m)update(x,v,lson);
else update(x,v,rson);
up(L,R,pos);
}
int query(int l,int r,int L,int R,int pos)
{
if(l<=L&&r>=R)
return ssum[pos];
int mid;
int ans=;
if(l<=m)ans=max(ans,query(l,r,lson));
if(r>m)ans=max(ans,query(l,r,rson));
if(num[m]<num[m+])
ans=max(ans,min(m-l+,rsum[pos<<])+min(r-m,lsum[pos<<|] ));
return ans;
} int main()
{
char s[];
int cas;
scanf("%d",&cas);
while(cas--)
{
int n,q;
scanf("%d%d",&n,&q);
build(,n,);
while(q--)
{
int a,b;
scanf("%s%d%d",s,&a,&b);
if(s[]=='Q')
printf("%d\n",query(a+,b+,,n,));
else
update(a+,b,,n,);
}
}
return ;
}

LCIS hdu3308 (线段树 区间合并)的更多相关文章

  1. HDU3308 线段树区间合并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 ,简单的线段树区间合并. 线段树的区间合并:一般是要求求最长连续区间,在PushUp()函数中实 ...

  2. (简单) HDU 3308 LCIS,线段树+区间合并。

    Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. ( ...

  3. LCIS(线段树区间合并)

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3308 LCIS Time Limit: 6000/2000 MS (Java/Others)     ...

  5. hdu3308 线段树——区间合并

    更新一个点: 求某个区间的最长连续上升序列: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 #include <cstdio> #in ...

  6. hdu3308 线段树 区间合并

    给n个数字 U表示第A个数改为B.A是从0开始. Q输出最大的递增序列个数. 考虑左边,右边,和最大的. #include<stdio.h> #define lson l,m,rt< ...

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

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

  8. LCIS HDU - 3308 (线段树区间合并)

    LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...

  9. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

随机推荐

  1. R vs Python,数据分析中谁与争锋?

    R和Python两者谁更适合数据分析领域?在某些特定情况下谁会更有优势?还是一个天生在各方面都比另一个更好? 当我们想要选择一种编程语言进行数据分析时,相信大多数人都会想到R和Python——但是从这 ...

  2. [SDOI2017]硬币游戏

    考虑生成函数来做 g(x)函数就是0+0*x+...+1*x^s+...+|∑|^(n-s)x^n 就是最后s位必须填这个串,但是前面随便填的方案数 然后枚举之前出现了哪个串(包括自己),如果没有相交 ...

  3. HDU 5574 Colorful Tree

    • 给出一棵树,每个点有初始的颜色,支持两种操作• 将一个点的子树染成一种给定颜色• 问一个点的子树里有几种不同的颜色 •

  4. 洛谷P2605 基站选址

    神TM毒瘤线段树优化DP......新姿势get. 题意:有n个村庄,在里面选不多于k个建立基站. 建立基站要ci的费用.如果一个村庄方圆si内没有基站,那么又要支出wi的费用.求最小费用. 解:很显 ...

  5. bug5 Debug:This kind of launch is configured to openthe debug perspective when it解决办法

    启动tomcat时,myeclipse报错: This kind of launch is configured to openthe debug perspective when itsuspend ...

  6. 「Vue」路由

    Vue-routerrouter-link active-class类型: string默认值: "router-link-active"设置 链接激活时使用的 CSS 类名.默认 ...

  7. HTTP header location 重定向 URL

    http头信息 头信息的作用很多,最主要的有下面几个:1.跳转当浏览器接受到头信息中的 Location: xxxx 后,就会自动跳转到 xxxx 指向的URL地址,这点有点类似用 js 写跳转.但是 ...

  8. vue中的this指向问题

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. Facebook人工智能实验室的前世今生

    Facebook人工智能实验室的前世今生 是时候停止把Facebook当作纯粹的社交媒体公司来看了.它用无人机提供互联网服务,为了发展虚拟现实而收购Oculus,不懈追求人工智能,Facebook已经 ...

  10. 安装mongodb以及设置为windows服务 详细步骤

    我的win7 32的,注意版本要正确! 一.下载mongodb压缩包:mongodb-win32-i386-2.6.9.zip() 二.在D盘新建文件夹mongodb,将压缩我的解压文件放进去(有一个 ...