题意:

U A B: 把第A个数变成B
Q A B: 输出【A,B】最长连续上升子序列(注意是连续  相当于子串)

思路:单点更新 ,区间合并几下左边开头最小  和右边结束最大的两个数即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <iostream>
#define lson (i<<1)
#define rson (i<<1|1)
#define N 100050
using namespace std;
int lsum[N*],rsum[N*],msum[N*];
int lmaxn[N*],rmaxn[N*];
int a[N];
int max(int x,int y)
{
return x>y?x:y;
}
int min(int x,int y)
{
return x<y?x:y;
}
void pushup(int i,int l,int r)
{
int mid=(l+r)>>;
lsum[i]=lsum[lson];
rsum[i]=rsum[rson];
if(lsum[i]==mid-l+&&rmaxn[lson]<lmaxn[rson])
lsum[i]+=lsum[rson];
if(rsum[i]==r-mid&&rmaxn[lson]<lmaxn[rson])
rsum[i]+=rsum[lson];
msum[i]=max(msum[lson],msum[rson]);
if(rmaxn[lson]<lmaxn[rson])
msum[i]=max(msum[i],rsum[lson]+lsum[rson]);
lmaxn[i]=lmaxn[lson];
rmaxn[i]=rmaxn[rson];
}
void build(int l,int r,int i)
{
if(l==r)
{
lsum[i]=rsum[i]=msum[i]=; lmaxn[i]=rmaxn[i]=a[l];
return ;
}
int mid=(l+r)>>;
build(l,mid,lson);
build(mid+,r,rson);
pushup(i,l,r);
}
void update(int l,int r,int p,int va,int i)
{
if(l==r)
{
lmaxn[i]=rmaxn[i]=va;
return ;
}
int mid=(l+r)>>;
if(p<=mid)update(l,mid,p,va,lson);
else update(mid+,r,p,va,rson);
pushup(i,l,r);
}
int query(int l,int r,int pl,int pr,int i)
{
if(l>=pl&&r<=pr)
{
return msum[i];
}
int mid=(l+r)>>;
if(pr<=mid)return query(l,mid,pl,pr,lson);
else if(pl>mid)return query(mid+,r,pl,pr,rson);
else
{ int maxn1=,maxn2=;
maxn1=query(l,mid,pl,mid,lson);
maxn2=query(mid+,r,mid+,pr,rson);
maxn1=max(maxn1,maxn2);
if(rmaxn[lson]<lmaxn[rson])
{
int tmp=min(rsum[lson],mid-pl+)+min(lsum[rson],pr-mid);
maxn1=max(maxn1,tmp);
}
return maxn1;
}
}
int main() {
int tt,n,m;
scanf("%d",&tt);
while(tt--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
build(,n,);
while(m--)
{
char c;
int l,r;
scanf(" %c%d%d",&c,&l,&r); if(c=='U')
{
l++;
update(,n,l,r,);
}else
{
l++;r++;
printf("%d\n",query(,n,l,r,));
}
}
}
return ;
}

HDU 3308 LCIS的更多相关文章

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

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

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

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

  3. HDU 3308 LCIS(线段树)

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

  4. hdu 3308 LCIS 线段树

    昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...

  5. 线段树(区间维护):HDU 3308 LCIS

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

  6. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

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

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

  8. HDU 3308 LCIS (经典区间合并)【线段树】

    <题目链接> 题目大意: 给你一段序列,对其进行两种操作,一是修改某个序号的点的值:二是查询某个区间的LCIS(最长上升子序列). 解题分析: 线段树区间合并的典型例题,用求某个区间的LC ...

  9. HDU 3308 LCIS (线段树&#183;单点更新&#183;区间合并)

    题意  给你一个数组  有更新值和查询两种操作  对于每次查询  输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并  线段树维护三个值  相应区间的LCIS长度(lcis)  相应区间以左 ...

  10. HDU 3308 LCIS(线段树)

    题目链接 模板题吧,忘了好多,终于A了... #include <cstring> #include <cstdio> #include <string> #inc ...

随机推荐

  1. java多线程编程--基础篇

    一.基本概念 a.操作系统中进程与线程的概念 现在的操作系统是多任务操作系统.多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间, 一个进程中可以启动 ...

  2. Linq To Sqlite 一一二二

    说在前头 之所以写下这些文字,主要是因为使用LINQ的同志们都觉它的美好(至于有多美好,各位心里知道,我就不在描述了,如果你是你还不了解LINQ,园子里有大把的文章),微软老哥只提供了自家的SQLSe ...

  3. 在win 7 vs2013下 web 调试 出现“ iis Express Worker Process 已停止工作”错误

    在win 7 vs2013下 web 调试 出现“ iis Express Worker Process 已停止工作”错误: 如下图:   最终解决方案如下: 用管理员身份运行CMD,输入netsh  ...

  4. [python]WindowsError的错误代码详解

    转自:http://www.aichengxu.com/view/46906 WindowsError的错误代码详解 0操作成功完成. 1功能错误. 2系统找不到指定的文件. 3系统找不到指定的路径. ...

  5. Windows:常见问题

    1.文件(夹)非法字符 Windows系统文件(夹)非法字符"\\/:*?\"<>|",不包含‘.’,但"."字符不能是文件(夹)的首字符 ...

  6. tomcat配置SSL证书(使用startSSL申请到的证书)

    1. 生成p12证书 生成完成后,下载保存. 2. 将p12文件上传至服务器上的tomcat/keystore/上,此处取名为test.com.p12 3. 修改tomcat/conf/server. ...

  7. 【前端】String.prototype.match() 用法详解

    var str="1 plus 2 equal 3" // 正则表达式 console.log(str.match(/\d+/g)); // ["1", &qu ...

  8. R----DT包介绍学习

    DT包:查看矩阵或数据框的内容 12 library(DT)datatable(iris, options = list(pageLength = 5)) DT包提供大量UI定制功能,即修改展示的HT ...

  9. [问题2014S14] 解答

    [问题2014S14]  解答 首先, 满足条件的 \(\varphi\) 的全体特征值都为零. 事实上, 任取 \(\varphi\) 的特征值 \(\lambda\), 对应的特征向量为 \(0\ ...

  10. jQuery验证元素是否为空的两种常用方法

    这篇文章主要介绍了jQuery验证元素是否为空的两种常用方法,实例分析了两种常用的判断为空技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了jQuery验证元素是否为空的两种常用方法.分享给 ...