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. 20145237《Java程序设计》实验报告一

    实验一 Java开发环境的熟悉(Windows + Eclipse) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验要求 1 ...

  2. Python choice() 函数

    Python choice() 函数  Python 数字 描述 choice() 方法返回一个列表,元组或字符串的随机项. 语法 以下是 choice() 方法的语法: import random ...

  3. Document Object Model

    什么是DOM W3C制定的书写HTML分析器的标准接口规范 全称 Document Object Model 文档对象模型DOM为HTML文档提供的一个API(接口) 可以操作HTML文档 <! ...

  4. WebApi一个控制器中定义多个Get方法。

    问题:怎样解决一个ApiController中定义多个Get方法或者Post方法? 答:要想实现一个ApiController中定义多个Get方法或者Post方法,则需要在WebApiConfig类中 ...

  5. WPF自学入门(十一)WPF MVVM模式Command命令

    在WPF自学入门(十)WPF MVVM简单介绍中的示例似乎运行起来没有什么问题,也可以进行更新.但是这并不是我们使用MVVM的正确方式.正如上一篇文章中在开始说的,MVVM的目的是为了最大限度地降低了 ...

  6. django处理cookie的机制

    title: django处理cookie的机制 tags: djaogo, cookie, session grammar_cjkRuby: true --- cookie的意义 在多数日常使用的网 ...

  7. vSphere Client 搭建Windows server 2008 r2 服务器指南

    下载准备 下载并安装vSphere Client 链接:https://pan.baidu.com/s/1v0IrGrMjpA2FGeqagaJN-g 密码:zzd1 下载Windows server ...

  8. redis入门(02)redis的常见问题

    一.常见问题 1.安装遇到/bin/sh: cc: command not found 解决办法:安装gcc yum install gcc 2.后台启动server端 2.1.问题现象 2.2.解决 ...

  9. Oracle处理XML字段时遇到的ORA-31013: XPATH 表达式无效问题

    select extractValue(ed.info_id, '/Root/ExpandProfile/PhoneNumber') as phone, extractValue(ed.info_id ...

  10. python 迭代器 生成器

    迭代器 生成器 一 什么是迭代器协议 1.迭代器协议是指:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个StopIteration异常,以终止迭代 (只能往后走不能往前 ...