LCIS

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

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
 
题意:求区间连续递增的最大个数,Q是询问区间内最大的LCIS

U是更新节点

 
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + ;
int llen[maxn << ], rlen[maxn << ], len[maxn << ], tree[maxn];
void pushup(int l, int r, int id)
{
int m = (l + r) >> ;
llen[id] = llen[id << ];
rlen[id] = rlen[id << | ];
if (tree[m + ] > tree[m])
{
if (llen[id << ] == m - l + )
llen[id] += llen[id << | ];
if (rlen[id << | ] == r - m)
rlen[id] += rlen[id << ];
len[id] = max(max(len[id << ], len[id << | ]), rlen[id << ] + llen[id << | ]);
}
else
len[id] = max(len[id << ], len[id << | ]);
}
void build(int l, int r, int id)
{
if (l == r)
{
scanf("%d", &tree[l]);
len[id] = llen[id] = rlen[id] = ;
return;
}
int m = (l + r) >> ;
build(l,m,id<<);
build(m+,r,id<<|);
pushup(l, r, id);
}
int query(int ll, int rr, int l, int r, int id)
{
if (ll <= l && r <= rr)
return len[id];
int m = (l + r) >> ;
if (ll <= m && m < rr)
{
int l1 = query(ll, rr, l,m,id<<);
int l2 = query(ll, rr, m+,r,id<<|);
if (tree[m] < tree[m + ])
{
int le = max(ll, m - rlen[id << ] + );
int ri = min(rr, m + llen[id << | ]);
return max(max(l1, l2), ri - le + );
}
return max(l1, l2);
}
else if (rr <= m)
return query(ll, rr, l,m,id<<);
else
return query(ll, rr, m+,r,id<<|);
} void update(int a, int b, int l, int r, int id)
{
if (a == l && a == r)//找到要更新的位置
{
tree[a] = b;
return;
}
int m = (l + r) >> ;
if (m >= a)
update(a, b, l,m,id<<);
else
update(a, b, m+,r,id<<|);
pushup(l, r, id);
}
int main()
{
int t;
scanf("%d\n", &t);
while (t--)
{
int n, m;
scanf("%d%d", &n, &m);
build(, n - , ); while (m--)
{
char c[];
int a, b;
scanf("%s %d %d", c, &a, &b);
if (c[] == 'Q')
printf("%d\n", query(a, b, , n - , ));
else
update(a, b, , n - , );
}
}
return ;
}

hdu 3308 线段树,单点更新 求最长连续上升序列长度的更多相关文章

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

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

  2. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

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

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

  4. HDU 1394 Minimum Inversion Number (线段树 单点更新 求逆序数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给你一个n个数的序列,当中组成的数仅仅有0-n,我们能够进行这么一种操作:把第一个数移到最 ...

  5. HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)

    题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...

  6. HDU 2795 线段树单点更新

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. hdu 1166 线段树单点更新

    等线段树复习完再做个总结 1101 2 3 4 5 6 7 8 9 10Query 1 3Add 3 6Query 2 7Sub 10 2Add 6 3Query 3 10End Case 1:633 ...

  8. BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 10374  Solved: 4535[Subm ...

  9. HDU 2795 (线段树 单点更新) Billboard

    h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子. 每次找能放纸条而且是最上面的位置,询问完以后可以同时更新,所以可以把update和query写在同一个函数里. #include ...

随机推荐

  1. 【剑指Offer面试编程题】题目1515:打印1到最大的N位数--九度OJ

    题目描述: 给定一个数字N,打印从1到最大的N位数. 输入: 每个输入文件仅包含一组测试样例. 对于每个测试案例,输入一个数字N(1<=N<=5). 输出: 对应每个测试案例,依次打印从1 ...

  2. CNN反向传播算法公式

    网络结构(6c-2s-12c-2s): 初始化: \begin{align}\notag W \sim U(- \frac{\sqrt{6}}{\sqrt{n_j+n_{j+1}}} , \frac{ ...

  3. Gcd&Exgcd

    欧几里得算法: \[gcd(a,b)=gcd(b,a\bmod b)\] 证明: 显然(大雾) 扩展欧几里得及证明: 为解决一个形如 \[ax+by=c\] 的方程. 根据裴蜀定理,当且仅当 \[gc ...

  4. 网络流的最大流入门(从普通算法到dinic优化)

    网络流(network-flows)是一种类比水流的解决问题方法,与线性规划密切相关.网络流的理论和应用在不断发展.而我们今天要讲的就是网络流里的一种常见问题--最大流问题. 最大流问题(maximu ...

  5. 通过SparkListener监控spark应用

    监控spark应用的方式比较多,比如spark on yarn可以通过yarnClient api监控.这里介绍的是spark内置的一种监控方式 如果是sparkStreaming,对应的则是stre ...

  6. 通过css 居中div的几种常用方法

    1.text-align:center方式 .center{ text-align:center; } center_text{ display:inline-block; width:500px } ...

  7. python2学习------基础语法1 (变量、分支语句、循环语句、字符串操作)

    1.变量类型 Numbers(数字):int,float,long String(字符串) List(列表) tuple(元组) dict(字典) bool(布尔):True,False # 删除变量 ...

  8. java 搭积木

    搭积木 小明最近喜欢搭数字积木, 一共有10块积木,每个积木上有一个数字,0~9. 搭积木规则: 每个积木放到其它两个积木的上面,并且一定比下面的两个积木数字小. 最后搭成4层的金字塔形,必须用完所有 ...

  9. 新手小白如何向GitHub上提交项目

    首先你得注册一个自己的GitHub账号,注册网址:https://github.com/join 创建一个新的项目,填写项目名称,描述 创建完成之后,跳转到下面的页面,下面红框中的网址要记住,在后面上 ...

  10. Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案

    原文地址:http://blog.csdn.net/u_xtian/article/details/7495023 这个看似简单的问题困扰了我好久了,我已经google了很多相关的信息了,但是在我看来 ...