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. 2017-2018-1 我爱学Java 第六七周 作业

    团队六七周作业 完善版需求规格说明书 制定团队编码规范 数据库设计 后端架构设计 TODOList 参考资料 完善版需求规格说明书 <需求规格说明书>初稿不足之处: 1.开发工具写错 2. ...

  2. Android webview Mixed Content无法显示图片解决

    转自:http://blog.csdn.net/crazy_zihao/article/details/51557425 前言 在使用WebView加载https资源文件时,如果认证证书不被Andro ...

  3. git cherry-pick 整理

    git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作.例如,假设我们有个稳定版本的分支,叫v2.0,另外还有个开发版本的分支v3.0,我们不能直接把两个分支合并, ...

  4. java截取一个字符串正数或倒数某个特定字符前后的内容

    取出正数第二个“.”后面的内容 public class TestCode { public static void main(String[] args) { String str ="2 ...

  5. Django rest framework源码分析(4)----版本

    版本 新建一个工程Myproject和一个app名为api (1)api/models.py from django.db import models class UserInfo(models.Mo ...

  6. python-map的用法

    map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 1.当seq只 ...

  7. Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1

    摘要: Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1 安装遇到问题请文末留言. 悦动智能公众号:aibbtcom AI这个概念好像突然就 ...

  8. GIT入门笔记(14)- 链接到远程仓库

    1.远程仓库地址https://github.com/ 2.注册远程仓库账号 3.生成ssh-key,并配置到github 由于你的本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以, ...

  9. 关于阿里巴巴iconfont的使用方法

    iconfont网址:http://www.iconfont.cn/ 说起iconfont,做前端开发的应该知道它的好处,图标库之丰富,只有你想不到的,没有你找不到的,而且轻量高清.用户在iconfo ...

  10. python中 functools模块 闭包的两个好朋友partial偏函数和wraps包裹

    前一段时间学习了python当中的装饰器,主要利用了闭包的原理.后来呢,又见到了python当中的functools模块,里面有很多实用的功能.今天我想分享一下跟装饰器息息相关的两个函数partial ...