HDU3308 LCIS
Time Limit: 2000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
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
Each case starts with two integers n , m(0<n,m<=10 5).
The next line has n integers(0<=val<=10 5).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=10 5)
OR
Q A B(0<=A<=B< n).
Output
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
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
using namespace std;
const int mxn=;
int n,m;
int d[mxn];
struct node{
int cnt;int lans,rans;
}t[mxn<<];
void update(int p,int l,int r,int rt){
if(l==r)return;
int mid=(l+r)>>;
if(p<=mid)update(p,ls);
else update(p,rs);
t[rt].cnt=max(t[rt<<].cnt,t[rt<<|].cnt);
t[rt].lans=t[rt<<].lans;t[rt].rans=t[rt<<|].rans;
if(d[mid]<d[mid+]){
t[rt].cnt=max(t[rt].cnt,t[rt<<].rans+t[rt<<|].lans);
if(t[rt<<].lans==mid-l+)
t[rt].lans=t[rt<<].lans+t[rt<<|].lans;
if(t[rt<<|].rans==r-mid)
t[rt].rans=t[rt<<|].rans+t[rt<<].rans;
}
return;
}
void Build(int l,int r,int rt){
if(l==r){
t[rt].cnt=t[rt].lans=t[rt].rans=;
return;
}
int mid=(l+r)>>;
Build(ls);
Build(rs);
t[rt].cnt=max(t[rt<<].cnt,t[rt<<|].cnt);
t[rt].lans=t[rt<<].lans;
t[rt].rans=t[rt<<|].rans;
if(d[mid]<d[mid+]){
t[rt].cnt=max(t[rt].cnt,t[rt<<].rans+t[rt<<|].lans);
if(t[rt<<].lans==mid-l+)
t[rt].lans=t[rt<<].lans+t[rt<<|].lans;
if(t[rt<<|].rans==r-mid)
t[rt].rans=t[rt<<|].rans+t[rt<<].rans;
}
return;
}
int query(int L,int R,int l,int r,int rt){
if(L<=l && r<=R) return t[rt].cnt;
int mid=(l+r)>>;
if(R<=mid)return query(L,R,ls);
if(mid<L)return query(L,R,rs);
else{
int res=max(query(L,R,ls),query(L,R,rs));
if(d[mid]<d[mid+]){//如果结点所存答案长于区间长度,实际答案等于区间长度,用min维护
res=max(res,(min(t[rt<<].rans,mid-L+)+min(t[rt<<|].lans,R-mid)));
}
return res;
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
memset(t,,sizeof );
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)scanf("%d",&d[i]);
Build(,n,);
char op[];int a,b;
for(i=;i<=m;i++){
scanf("%s%d%d",op,&a,&b);
if(op[]=='U'){
d[++a]=b;
update(a,,n,);
}
if(op[]=='Q'){ printf("%d\n",query(a+,b+,,n,));
}
}
}
return ;
}
HDU3308 LCIS的更多相关文章
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU-3308 LCIS(区间合并)
题目大意:给一个整数序列,m次询问,每次询问某个区间中最长连续上升子序列的长度. 题目分析:线段树区间合并.维护以区间左端开头的.以区间右端点结尾的和区间最长的上升连续序列. 代码如下: # incl ...
- HDU3308(LCIS) 线段树好题
题目链接:传送门 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y 2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 题目思路: ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
- 【转】线段树完全版~by NotOnlySuccess
线段树完全版 ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...
- 《完全版线段树》——notonlysuccess
转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...
- 【转】 线段树完全版 ~by NotOnlySuccess
载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...
- 【转载】完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...
随机推荐
- LOL游戏基本代码
class Hero: def __init__(self, new_nickname, new_aggressivity, new_life_value, new_money, new_armor ...
- php五种常见的设计模式
工厂模式 工厂模式是最常用的实例化对象的模式,是用工厂方法代替new操作的一种模式 使用工厂模式的好处是:如果想要更改实例化的类名,则只需要更改该工厂方法内容即可,不需逐一寻找代码中具体实例化的地方( ...
- LeetCode#5 两个排序数组的中位数
给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 你可以假设 nums1 和 nums2 ...
- 18.VUE学习之-v-for操作对象与数值
一组数组时的循环 二组数组时的循环 另外可以v for 20 可以直接操作数字 <!DOCTYPE html> <html lang="en"> <h ...
- SQLite3 of python
SQLite3 of python 一.SQLite3 数据库 SQLite3 可使用 sqlite3 模块与 Python 进行集成,一般 python 2.5 以上版本默认自带了sqlite3模块 ...
- Python入门必学:递归函数正确的操作使用方法,案例详解
递归函数,在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 举个例子,我们来计算阶乘n! = 1 x 2 x 3 x ... x n,用函数fact(n)表示,可以 ...
- Admin站点
使用admin站点 a.在settings.py中设置语言和时区 LANGUAGE_CODE = 'zh-hans' # 使用中国语言 TIME_ZONE = 'Asia/Shanghai' # 使用 ...
- 组装需要的json数据格式
在实际项目中有时候会遇到一些有特殊要求的控件,比如easyui-combogrid,加载的并不是常见的json格式,这里我遇到过需要加载类似省市县这种三级数据格式.最后也是从别人的博客中学到的如何组装 ...
- loj2043 「CQOI2016」K 远点对
k-d tree 裸题------ #include <algorithm> #include <iostream> #include <cstdio> using ...
- C++ map 的用法归纳2
[尊重原著: http://blog.csdn.net/zcf1002797280/article/details/7847819] Map是c++的一个标准容器,它提供了很好一对一的关系,在一些程序 ...