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. [Database] MAC MySQL中文乱码问题

    1 确保数据库编码设置, 可修改my.cnf mysql> show variables like '%character%'; +--------------------------+---- ...

  2. luogu P2761 软件补丁问题

    网络流(x) 状压(√) 初始状态为全1,合法状态为(state&b1)&(state|b1) == state && (state&b2)&(stat ...

  3. css常用设置

    距离左边和上边 style="margin-left:100px;margin-top:10px" 设置相对位置 position:absolute; position:relat ...

  4. Ecshop系统二次开发教程及流程演示

      来源:互联网 作者:佚名 时间:03-01 16:05:31 [大 中 小] Ecshop想必大家不会觉得陌生吧,大部分的B2C独立网店系统都用的是Ecshop系统,很受用户的喜爱,但是由于Ecs ...

  5. Hive的原生部署方式

    一.Hive的部署 1.官方文档 https://cwiki.apache.org/confluence/display/Hive/GettingStarted 2.前提条件 需要安装JDK1.7之上 ...

  6. SQL注入的原理及分析

    注入攻击的本质:将用户输入的数据当做代码执行. 有2个限制条件: 1.用户能够控制输入. 2.原本程序要执行的代码,拼接了用户输入的数据后进行执行. 定义:用户输入的数据被当做SQL语句执行. 以下面 ...

  7. python操作mongoDB(pymongo的使用)

    pymongo操作手册 连接数据库 方法一(推荐) import pymongo client = pymongo.MongoClient(host="localhost",por ...

  8. C++面试常见问题——13结构体与共用体的sizeof

    结构体与共用体的sizeof 结构体的sizeof 结构体变量占用的内存空间大小通常是其基本类型的大小,但是由例外(字节对齐机制) struct S1{ char c[5]; int a; doubl ...

  9. SQL中的Where,Group By,Order By和Having

    说到SQL语句,大家最开始想到的就是他的查询语句: select * from tableName: 这是最简单的一种查询方式,不带有任何的条件. 当然在我们的实际应用中,这条语句也是很常用到的,当然 ...

  10. Docker退出容器不关闭容器的方法

    进入docker容器后如果退出容器,容器就会变成Exited的状态,那么如何退出容器让容器不关闭呢? 如果要正常退出不关闭容器,请按Ctrl+P+Q进行退出容器,这一点很重要,请牢记! 以下示例为退出 ...