题意:

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. 11.写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名

    //首先列出需要被操作的url     $url_path = "http://www.sina.com.cn/abc/de/fg.php?id=1";     方法一:     ...

  2. Ruby(rails)win环境下安装

    1.RubyInstaller 在RubyInstaller官网下载window版本安装,地址:http://rubyinstaller.org/downloads/  执行安装程序,勾选Add Ru ...

  3. [ruby]Windows Ruby安装步骤

    Windows Ruby 安装步骤 准备工作: 1.http://rubyinstaller.org/downloads/ 下载选择Ruby 1.9.3 2.http://rubyinstaller. ...

  4. 【数论】Miller_Rabin

    Miller_Rabin素数测试     Miller_Rabin判断单个素数的方法运用了费马小定理,可以说非常之快了.     Miller_Rabin曾经被称作“黑科技”,但是根据费马小定理其实完 ...

  5. 解决ADB端口占用问题

    方式一5037为adb默认端口,若5037端口被占用,查看占用端口的进程PIDC:\Users\wwx229495>netstat -aon|findstr 5037   TCP    127. ...

  6. wcf服务与web发布时无法访问 几种解决办法

    1   如果wcf服务与web发布在同一iis目录下,没有跨域的问题   但发布前要修改 ServiceReferences.ClientConfig 把wcf服务地址改为你发布后的iis的ip地址( ...

  7. ASCII编码表

    最初的编码:ASCII 补充: ASCII表是适用于美国的,共128位:ISO-8859-1是适用于欧洲的,共256位 :GB2312是适用于中文系统的:UTF-8是万国码,适用于绝大部分语言:ANS ...

  8. python 笔记

    第一周2016/9/11   Python 2.0和3.0的区别 3.0 的模块名改了和之前的2.0 不一样 #!/usr/bin/env python # -*- coding:utf-8 -*- ...

  9. [课程设计]Scrum 2.5 多鱼点餐系统开发进度(下单一览页面-菜式添加框架设计)

    Scrum 2.5 多鱼点餐系统开发进度  (下单一览页面-菜式添加框架设计) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题 ...

  10. LA 5135 井下矿工

    题目链接:http://vjudge.net/contest/141787#problem/B 白书P318 题目大意:有N个矿井 ,由一些隧道连接起来,现在要修建尽量少的安全通道,使得无论哪里发生事 ...