题意  给你一个数组  有更新值和查询两种操作  对于每次查询  输出相应区间的最长连续递增子序列的长度

基础的线段树区间合并  线段树维护三个值  相应区间的LCIS长度(lcis)  相应区间以左端点为起点的LCIS长度(lle)  相应区间以右端点为终点的LCIS长度(lri)  然后用val存储数组相应位置的值  当val[mid + 1] > val[mid] 的时候就要进行区间合并操作了

#include <cstdio>
#include <algorithm>
#define lc lp, s, mid
#define rc rp, mid+1, e
#define lp p<<1
#define rp p<<1|1
#define mid ((s+e)>>1)
using namespace std;
const int N = 100005, M = N * 4;
int lcis[M], lle[M], lri[M], val[N]; void pushup(int p, int s, int e)
{
lcis[p] = max(lcis[lp], lcis[rp]);
lle[p] = lle[lp], lri[p] = lri[rp];
if(val[mid + 1] > val[mid]) //合并条件
{
lcis[p] = max(lcis[p], lri[lp] + lle[rp]);
if(lle[lp] == mid + 1 - s) lle[p] += lle[rp];
if(lri[rp] == e - mid) lri[p] += lri[lp];
}
} void build(int p, int s, int e)
{
if(s == e)
{
lcis[p] = lle[p] = lri[p] = 1;
scanf("%d", &val[s]);
return;
}
build(lc);
build(rc);
pushup(p, s, e);
} void update(int p, int s, int e, int x, int v)
{
if(s == e)
{
val[s] = v;
return;
}
if(x <= mid) update(lc, x, v);
else if(x > mid) update(rc, x, v);
pushup(p, s, e);
} int query(int p, int s, int e, int l, int r)
{
if(l <= s && e <= r) return lcis[p];
int ret = 0;
if(val[mid + 1] > val[mid])
ret = min(r, mid + lle[rp]) - max(l, mid + 1 - lri[lp]) + 1;
if(l <= mid) ret = max(ret, query(lc, l, r));
if(r > mid) ret = max(ret, query(rc, l, r));
return ret;
} int main()
{
int T, n, m, a, b;
char op[5];
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
build(1, 0, n - 1);
while(m--)
{
scanf("%s%d%d", op, &a, &b);
if(op[0] == 'Q')
printf("%d\n", query(1, 0, n - 1, a, b));
else update(1, 0, n - 1, a, b);
}
}
return 0;
}

LCIS

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
 

HDU 3308 LCIS (线段树&#183;单点更新&#183;区间合并)的更多相关文章

  1. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  2. POJ 2892 Tunnel Warfare(线段树单点更新区间合并)

    Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 D ...

  3. hdu1540之线段树单点更新+区间合并

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. hdu 5316 Magician(2015多校第三场第1题)线段树单点更新+区间合并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5316 题意:给你n个点,m个操作,每次操作有3个整数t,a,b,t表示操作类型,当t=1时讲a点的值改 ...

  5. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  6. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  8. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  9. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  10. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

随机推荐

  1. Installing Metasploit Framework on Ubuntu 14.04 LTS and Debian 7

    原文链接:http://www.darkoperator.com/installing-metasploit-in-ubunt/ This Guide covers the installation ...

  2. vue.js源码学习分享(六)

    /* */ /* globals MutationObserver *///全局变化观察者 // can we use __proto__?//我们能用__proto__吗? var hasProto ...

  3. 标准C程序设计七---111

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  4. unix网络编程第一章demo

    之前一直以为time_wait状态就是主动关闭的那一方产生.然后这个端口一直不可以用.实际我发现服务端监听一个端口.客户端发来连接后.传输数据后.服务端关闭客户端套接字后.用netstat -nat ...

  5. checkbox 复选框只能选中一次,之后不能用

    <td> <input type="checkbox" name="is_check" id="is_check" val ...

  6. DataTable.AcceptChanges的理解

    OleDbDataAdapter 怎么更新不了数据库?      String    tbName    =    ds.Tables[0].TableName;       String    te ...

  7. Truck History(最小生成树)

    poj——Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27703   Accepted: 10 ...

  8. Oracle服务扫描工具Oscanner

    Oracle服务扫描工具Oscanner   Oracle是甲骨文公司推出的关系型数据库,适用于中大规模数据存储,如大型企业.电信.银行等行业.Kali Linux集成了Oracle服务扫描专向工具O ...

  9. c实现的trim函数

    功能:去掉字符串首尾的空格,换行符等空白. 代码: #include <string.h> #include <stdio.h> #include <ctype.h> ...

  10. Java开发者使用C++写程序踩的坑

    笔者是一个很矛盾的人.平时用Java.但是一开始学习的时候学的是汇编语言,而且对C语言也很熟悉.为什么不学C++呢?是因为我可以完全用Java的编码规范去写C++.因此我不需要了解更多的诸如C++的命 ...