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

基础的线段树区间合并  线段树维护三个值  相应区间的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. java面试题之happens before原则

    JSR-133使用happens-before的概念来指定两个操作之间的执行顺序.由于这两个操作可以在一个线程内,也可以在不同线程之间.因此,JMM可以通过happens-before关系向程序员提供 ...

  2. bzoj1306: [CQOI2009]match循环赛(模拟爆搜)

    Input第一行包含一个正整数n,队伍的个数.第二行包含n个非负整数,即每支队伍的得分.Output输出仅一行,即可能的分数表数目.保证至少存在一个可能的分数表.Sample Input 6 5 6 ...

  3. python根据文件目录、文件类型和文件与当前时间差删除文件

    直接贴代码: 删除某个目录下的文件,不遍历木路下文件夹下的文件,根据时间差删除,默认7天 #!/usr/bin/python # -*- coding: gbk -*- import os impor ...

  4. Tomcat和JVM的性能调优总结

    Tomcat性能调优: 找到Tomcat根目录下的conf目录,修改server.xml文件的内容.对于这部分的调优,我所了解到的就是无非设置一下Tomcat服务器的最大并发数和Tomcat初始化时创 ...

  5. windows.open 以post的方式传递参数

    今天看到有篇文章寫到 windows.open 可以post方式傳遞參數,就趕緊照作看看,結果是可行的,感謝撰寫這篇文章的作者~ /** * window.open with post method  ...

  6. 【eclipse】设置默认编码格式为UTF-8

    需要设置的几处地方为: Window->Preferences->General ->Content Type->Text->JSP 最下面设置为UTF-8 Window ...

  7. 转 php simple test

    转自 后期移至 以下为汪大哥写的 yunlian服务监控 如何写监控代码 首先在tests目录下新建一个文件xxx.php.其中xxx为你的服务名. class XxxTestCase extends ...

  8. poj 1459(网络流)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 26688   Accepted: 13874 D ...

  9. poj 3204(最小割--关键割边)

    Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7 ...

  10. ES6 的Object.assign(target, source_1, ···)方法与对象的扩展运算符

    一.基本概念 Object.assign方法用来将源对象(source)的所有可枚举属性,复制到目标对象(target).它至少需要两个对象作为参数,第一个参数是目标对象,后面的参数都是源对象. Ob ...