hdu 3308 LCIS(线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=3308
LCIS
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
10 10
7 7 3 3 5 9 9 8 1 8
Q 6 6
U 3 4
Q 0 1
Q 0 5
Q 4 7
Q 3 5
Q 0 2
Q 4 6
U 6 10
Q 0 9
1
4
2
3
1
2
5
pid=2871">2871
pid=1255">1255
#include <iostream>
#include <cstdio> using namespace std; struct node
{
int l,r;
int mmax;
int lmax,rmax;
int lnum,rnum;
}s[100000*4+10]; void InitTree(int l,int r,int k)
{
s[k].l=l;
s[k].r=r;
s[k].mmax=1;
s[k].rmax=1;
s[k].lmax=1;
s[k].lnum=s[k].rnum=0;
if (l==r)
return ;
int mid=(l+r)/2;
InitTree(l,mid,2*k);
InitTree(mid+1,r,2*k+1);
} void UpdataTree(int i,int change,int k)
{
if (s[k].l==s[k].r&&s[k].l==i)
{
s[k].lnum=s[k].rnum=change;
return ;
}
int mid=(s[k].l+s[k].r)/2;
if (i>mid)
UpdataTree(i,change,2*k+1);
else if (i<=mid)
UpdataTree(i,change,2*k); s[k].lnum=s[k*2].lnum;
s[k].rnum=s[k*2+1].rnum; s[k].lmax=s[k*2].lmax;
s[k].rmax=s[k*2+1].rmax; s[k].mmax=max(s[k*2].mmax,s[k*2+1].mmax);
if(s[k*2].rnum<s[k*2+1].lnum)
{
s[k].mmax=max(s[k].mmax,s[k*2].rmax+s[k*2+1].lmax);
if(s[k*2].lmax==s[k*2].r-s[k*2].l+1)
s[k].lmax=s[k*2].lmax+s[k*2+1].lmax;
if(s[k*2+1].rmax==s[k*2+1].r-s[k*2+1].l+1)
s[k].rmax=s[k*2].rmax+s[k*2+1].rmax;
}
} int SearchTree(int l,int r,int k)
{
if (s[k].l==l&&s[k].r==r)
return s[k].mmax;
else
{
int mid=(s[k].l+s[k].r)/2;
if (l>mid)
return SearchTree(l,r,2*k+1);
else if (r<=mid)
return SearchTree(l,r,2*k);
/*else
{
if (s[k].lnum<s[k].rnum)
return SearchTree(l,mid,2*k)+SearchTree(mid+1,r,2*k+1);
else if
}*/
else
{
int a=min(s[k*2].rmax,mid-l+1);
int b=min(s[k*2+1].lmax,r-mid);
int Max=max(a,b);
Max=max(Max,SearchTree(l,mid,2*k));
Max=max(Max,SearchTree(mid+1,r,2*k+1));
if(s[k*2].rnum<s[2*k+1].lnum)
{
Max=max(Max,a+b);
}
return Max;
} }
} int main()
{
int t;
char ch[70];
scanf("%d",&t);
while (t--)
{
int n,m,w,a,b;
scanf("%d%d",&n,&m);
InitTree(0,n-1,1);
for (int i=0; i<n; i++)
{
scanf("%d",&w);
UpdataTree(i,w,1);
}
for (int i=0; i<m; i++)
{
//getchar();
scanf("%s%d%d",ch,&a,&b);
if (ch[0]=='Q')
{
//cout<<"!!!!!!!!!!!!!!!!!"<<endl;
int ans=SearchTree(a,b,1);
printf ("%d\n",ans); }
else if (ch[0]=='U')
{
UpdataTree(a,b,1);
}
}
}
return 0;
}
hdu 3308 LCIS(线段树区间合并)的更多相关文章
- HDU 3308 LCIS (线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...
- LCIS HDU - 3308 (线段树区间合并)
LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...
- HDU 3308 (线段树区间合并)
http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意: 两个操作 : 1 修改 单点 a 处的值. 2 求出 区间[a,b]内的最长上升子序列. 做法 ...
- HDU 3308 LCIS 线段树区间更新
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
- hud 3308 LCIS 线段树 区间合并
题意: Q a b 查询[a, b]区间的最长连续递增子序列的长度 U a b 将下表为a的元素更新为b 区间合并一般都有3个数组:区间最值,左区间最值和右区间最值 具体详见代码 #include & ...
- HDU 3308 LCIS (线段树·单点更新·区间合并)
题意 给你一个数组 有更新值和查询两种操作 对于每次查询 输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并 线段树维护三个值 相应区间的LCIS长度(lcis) 相应区间以左 ...
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- hdu 1540(线段树区间合并)
题目链接:传送门 参考文章:传送门 题意:n个数字初始连在一条线上,有三种操作, D x表示x号被摧毁: R 表示恢复剩下的通路 Q表示查询标号为x所在的串的最长长度. 思路:线段树的区间合并. #i ...
- hdu 3308 LCIS 线段树
昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...
随机推荐
- 使用开源库 Objective-C RegEx Categories 处理正则表达式
Objective-C RegEx Categories https://github.com/bendytree/Objective-C-RegEx-Categories 使用说明:将 RegExC ...
- python读取配置文件的方式
python读取配置文件的方式 1.从config.ini中读取,后缀无所谓,文件名字也无所谓,不过config.ini是常用写法,所谓见名知意 config.ini内容: [global] ip = ...
- 第二章 logstash - 输出插件之redis与es
最常用的两个输出插件: redis es 一.redis 1.用法 output { redis{ batch => false batch_events => 50 batch_time ...
- cesium and three.js【转】
https://blog.csdn.net/zhishiqu/article/details/79077883 这是威尔逊Muktar关于整合Three.js与铯的客人帖子.Three.js是一个轻量 ...
- libcurl进行HTTP GET获取JSON数据(转载)
转载:http://blog.csdn.net/vincent2610/article/details/68488365 #include <stdio.h> #include <i ...
- HDU—— 5159 Building Blocks
Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build blocks. LeL ...
- 矩阵中的旋转(Rotation)
参考的是<游戏和图形学的3D数学入门教程>,算是读书笔记吧. 目录 [隐藏] 1.2D中的旋转 2.3D中的旋转 2.1绕x轴旋转: 2.2绕Y轴旋转 2.3绕Z轴旋转 1.2D中的旋转 ...
- TRIZ系列-创新原理-13-反过来做原理
反过来做原理表述例如以下: 1)不直接接实施问题指出的动作,而是实施一个相反的动作;(比方用冷却取代加热等):2) 使物体或外部环境移动的部分精巧.或者使精巧的部分移动:3) 把物体上下颠倒.反过来做 ...
- NLP系列(4)_朴素贝叶斯实战与进阶(转)
http://blog.csdn.net/han_xiaoyang/article/details/50629608 作者: 寒小阳 && 龙心尘 时间:2016年2月. 出处:htt ...
- 转:Logistic regression (逻辑回归) 概述
Logistic regression (逻辑回归)是当前业界比较常用的机器学习方法,用于估计某种事物的可能性.比如某用户购买某商品的可能性,某病人患有某种疾病的可能性,以及某广告被用户点击的可能性等 ...