题意:

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. Extjs 3.4 复选框的,默认选中 ,禁用,(纯属于自己代码中需要,总结!)

    var sm = new Ext.grid.CheckboxSelectionModel( {         //一个特定的选择模型,它将渲染一列复选框,可以用来选择或反选多行数据.         ...

  2. 随机采样方法整理与讲解(MCMC、Gibbs Sampling等)

    本文是对参考资料中多篇关于sampling的内容进行总结+搬运,方便以后自己翻阅.其实参考资料中的资料写的比我好,大家可以看一下!好东西多分享!PRML的第11章也是sampling,有时间后面写到P ...

  3. JQ 操作 radio、checkbox 、select

    MXS&Vincene  ─╄OvЁ  &0000026─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好, ...

  4. 如何用jquery获取页面下HiddenField的值··

    怎么用jquery获取页面上HiddenField的值·· 怎么用jquery获取页面上HiddenField的值··?HiddenField的值是从后台赋值的··· 先赋值给Hiddenfield ...

  5. MVC中Razor的使用 及路径问题

    语法: @ 可以编写一条C#语句@{} 可以编写一组C#语句@: 将文字内容直接输出到页面上去@() 在一句中将一段C#代码包括起来,证明这一句完整的C#代码 引用命名空间:@using 空间名称 H ...

  6. 第九天 内容提供者 ContentResolver

    重点:理解ContentProvider 的作用和创建流程 1. 内容提供者,提供 其他数据库的访问. 特点       - 描述 : 它是android 四大组件之一,需要androidManife ...

  7. 15.Linux安装DHCP服务为虚拟机分配IP

    参考博客:http://www.jb51.net/article/31607.htm $ rpm -ql dhcp        #检查是否安装dhcp $ yum -y install dhcp*  ...

  8. HDU 5734 Acperience(返虚入浑)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  9. mac 安装 nginx 环境

    1.brew search nginx 2.brew install nginx 启动nginx ,sudo nginx ;访问localhost:8080 发现已出现nginx的欢迎页面了. 备注: ...

  10. window打开服务的dos命令

    window打开服务的dos命令   “开始”---> “运行”输入以下命令,或者Win + R,输入以下命令 对我比较有用的几个: 10. notepad--------打开记事本  31. ...