LCIS

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6066    Accepted Submission(s): 2634

Problem Description
Given n integers.
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].
 
Input
T in the first line, indicating the case number.
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).
 
Output
For each Q, output the answer.
 
Sample Input
1
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
Sample Output
1
1
4
2
3
1
2
5
Author
shǎ崽
 
Source
/*
hdu 3308 最长连续上升区间 给你n个数,然后是两个操作:
1.U A B 将第A个数替换成B
2.Q A B 查询[A,B]间的最长连续上升序列长度 看见题就感觉像前面写过的hdu1540最长连续序列,只是它那个序列是固定的
连续递增,只需要维护一下即可
所以在本题中我新增了lval,rval记录区间最左边和最右边的值,然后通过判断
这两个值来进行区间合并。同时用ls,rs,ms分别记录 从区间左端开始,区间
右端开始,整个区间 的最长连续上升序列 然后通过线段树来维护ls,rs,ms的值,然后查询进行一下判断即可 hhh-2016-03-31 19:50:28
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int maxn = 200050; struct node
{
int l,r;
int ls,rs,ms;
int lval,rval;
int mid()
{
return (l+r)>>1;
}
int len()
{
return (r-l+1);
}
} tree[maxn<<2]; void push_up(int i)
{
tree[i].ls = tree[lson].ls,tree[i].lval=tree[lson].lval;
tree[i].rs = tree[rson].rs,tree[i].rval=tree[rson].rval;
//如果可以合并(ls,rs可能超过区间的一般)
if(tree[i].ls == tree[lson].len() && tree[lson].rval < tree[rson].lval)
tree[i].ls += tree[rson].ls;
if(tree[i].rs == tree[rson].len() && tree[lson].rval < tree[rson].lval)
tree[i].rs += tree[lson].rs;
tree[i].ms = max(tree[lson].ms,tree[rson].ms);
if(tree[lson].rval < tree[rson].lval)
tree[i].ms = max(tree[i].ms,tree[lson].rs+tree[rson].ls);
//可能跨过了mid界限
} void build(int i,int l,int r)
{
tree[i].l = l,tree[i].r = r;
tree[i].ls=tree[i].rs=tree[i].ms=0;
tree[i].lval=tree[i].rval=0;
if(l == r)
{
scanf("%d",&tree[i].lval);
tree[i].rval = tree[i].lval;
tree[i].ls=tree[i].rs=tree[i].ms=1;
return ;
}
int mid = tree[i].mid();
build(lson,l,mid);
build(rson,mid+1,r);
push_up(i);
} void push_down(int i)
{ } void update(int i,int k,int va)
{
if(tree[i].l == k && tree[i].r == k)
{
tree[i].lval = va;
tree[i].rval = va;
return;
}
push_down(i);
int mid = tree[i].mid();
if(k <= mid)
update(lson,k,va);
else
update(rson,k,va);
push_up(i);
} int query(int i,int l,int r)
{
if(tree[i].l == l && tree[i].r == r)
{
return tree[i].ms;
}
int mid = tree[i].mid();
if(r <= mid)
return query(lson,l,r);
else if(l > mid)
return query(rson,l,r);
else
{
int ans1 = query(lson,l,mid);
int ans2 = query(rson,mid+1,r);
if(tree[lson].rval < tree[rson].lval) //如果可以合并(ls,rs有可能超出查询区间)
return max(max(ans1,ans2),min(tree[lson].rs,mid-l+1)+min(tree[rson].ls,r-mid));
else
return max(ans1,ans2);
}
}
char op[10];
int x,y;
int T,n,m;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
build(1,0,n-1); while(m--)
{
scanf("%s",op);
scanf("%d%d",&x,&y);
if(op[0] == 'Q')
{
printf("%d\n",query(1,x,y));
}
else
{
update(1,x,y);
}
}
}
return 0;
}

  

												

hdu 3308 最长连续上升区间的更多相关文章

  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,线段树+区间合并。

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

  3. HDU 3308 线段树单点更新+区间查找最长连续子序列

    LCIS                                                              Time Limit: 6000/2000 MS (Java/Oth ...

  4. HDU 2144 (最长连续公共子列 + 并查集) Evolution

    我发现我一直理解错题意了,这里的子序列指的是连续子序列,怪不得我写的LCS一直WA 顺便复习一下并查集 //#define LOCAL #include <iostream> #inclu ...

  5. HDU 3308 线段树求区间最长连续上升子序列长度

    题意:两种操作,Q L R查询L - R 的最长连续上升子序列长度,U pos val 单点修改值 #include <bits/stdc++.h> #define N 100005 us ...

  6. HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询

    题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...

  7. POJ 3667 & HDU 3308 & HDU 3397 线段树的区间合并

    看到讲课安排上 线段树有一节课"区间合并" 我是迷茫的 因为并没有见过 然后了解了一下题目 发现以前写过 还是很麻烦的树链剖分 大概是 解决带修改的区间查询"连续问题&q ...

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

    LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...

  9. HDU 3308 LCIS 线段树区间更新

    最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛  ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...

随机推荐

  1. Scrum 冲刺 第三日

    Scrum 冲刺 第三日 目录 要求 项目链接 燃尽图 问题 今日任务 明日计划 成员贡献量 要求 各个成员今日完成的任务(如果完成的任务为开发或测试任务,需给出对应的Github代码签入记录截图:如 ...

  2. 在linux中关闭防火墙

    1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...

  3. linux查看文件内容的常见命令

    1.cat命令,显示文件的所有内容,内容过多则显示最后一屏一般用于内容较少文件 2.more命令,分页显示文件的内容一般用于文件内容过多的文件,回车显示下一行,空格显示下一页,q/Q退出 3.head ...

  4. 利用封装、继承对Java代码进行优化

    注:本文实例分别可以在oldcastle(未优化的代码)和newcastle(优化后的代码)中查看,网址见文末 城堡游戏: 城堡中有多个房间,用户通过输入north, south, east, wes ...

  5. Lock(三)查看是谁把表给锁了

    查看是谁把表给锁了 select se1.inst_id as 被阻塞的会话节点, se2.inst_id as 罪魁祸首节点, se1.sid as 被阻塞的会话ID, ob.object_name ...

  6. Mego(04) - Mego入门

    本教程演示创建一个简单的数据库访问及更新数据的示例以便于初步了解下Mego框架的使用. 文中使用Visual Studio 2017版本. 创建Visual Studio项目 创建一个名为 MegoS ...

  7. layer ui插件显示tips时,修改字体颜色

    今天做调查问卷,又遇到一个蛋疼小问题,记录下. 调查问卷有很多选项是要求必填的,如果不填的话,需要给出友好的提示.用的如下组件:http://layer.layui.com/ 1.之前一直默认用的: ...

  8. python xml.dom模块解析xml

    1. 什么是xml?有何特征? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 例子:del.xml <?xml version=&q ...

  9. mysql 存储过程 实现数据同步

    数据库 表 发生变化,需要把2.0的表数据 同步到3.0库中去: -- 同步数据存储过程执行 -- 更新留言旧表数据到新表数据中 /*DEFINER:Vector*/ drop procedure i ...

  10. hdu1022 Train Problem I---模拟栈

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 车的进出站问题,先给出N个火车,再按序列一的方式进站,判断能否以序列二的方式出站,若 ...