题意:

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. 0525 Scrum 项目7.0

    一.sprint总结 本次sprint总结,本次合作每个人都完成了属于自己的任务,我觉得这是十分不错的,但是做出来的项目不够美观,内容可以更丰富一点,多样化一点,虽然每个人做出来的网页都各有各的区别, ...

  2. 使用 gulp 搭建前端环境入门篇(转载)

    本文转载自: 使用 gulp 搭建前端环境入门篇

  3. 用mysql++读写二进制

    方法1: // mysqlTest.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <mysql++.h> #inc ...

  4. lucene5.5 field

    lucene常见Field IntField 主要对int类型的字段进行存储,需要注意的是如果需要对InfField进行排序使用SortField.Type.INT来比较,如果进范围查询或过滤,需要采 ...

  5. windows进程详解

    1:系统必要进程system process    进程文件: [system process] or [system process]进程名称: Windows内存处理系统进程描述: Windows ...

  6. 自己写的java用jxl导出到excel工具

    package com; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; i ...

  7. CentOS 7数据库mysql和mariadb手动安装冲突的问题解决

    由于确定使用mysql,那只有卸载mariadb了. 一.首先查看当前安装的mariadb包 rpm -qa|grep mariadb 本人得到结果是:mariadb-libs-5.5.44-2.el ...

  8. charles抓包的使用教程

    // Charles 从入门到精通:(http://blog.csdn.net/donwei8/article/details/51647752) //抓包工具:Charles-断点修改 教程 (ht ...

  9. 整合Spring Data JPA与Spring MVC: 分页和排序

    之前我们学习了如何使用Jpa访问关系型数据库.比较完整Spring MVC和JPA教程请见Spring Data JPA实战入门,Spring MVC实战入门. 通过Jpa大大简化了我们对数据库的开发 ...

  10. AxureRP8实战手册(基础11-20)

    本文目录 基础11. 设置文本框输入为密码 基础12. 设置打开选择文件窗口 基础13. 限制文本框输入字符位数 基础14. 设置文本框提示文字 基础15. 设置文本框回车触发事件 基础16. 设置元 ...