LCIS

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

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
 
 
题解:

给你n个数组成的序列(序列中编号从0到n-1),有q次操作。

操作1——Q a  b,让你输出区间[a, b]里面最长的连续递增序列的长度;

操作2——U a  b,修改序列第a个数为b。

出了点小问题错了半天;

刚开始理解错了,是单调上升序列;1 3 5 7也算;

区间合并

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define SD(x,y) scanf("%lf%lf",&x,&y)
#define P_ printf(" ")
#define ll root<<1
#define rr root<<1|1
#define lson ll,l,mid
#define rson rr,mid+1,r
typedef long long LL;
const int MAXN=100010;
struct Node{
int len,lv,rv,lsum,rsum,sum;
Node init(int l,int r){
scanf("%d",&lv);rv=lv;
lsum=sum=rsum=1;
}
};
Node tree[MAXN<<2];
/*void print(int root,int l,int r){
int mid=(l+r)>>1;
if(l==r){
printf("%d %d\n",tree[root].lv,tree[root].rv);return;
}
print(lson);print(rson);
}*/ void pushup(int root){
tree[root].lsum=tree[ll].lsum;
tree[root].rsum=tree[rr].rsum;
tree[root].lv=tree[ll].lv;
tree[root].rv=tree[rr].rv;
tree[root].sum=max(tree[ll].sum,tree[rr].sum);
if(tree[ll].rv<tree[rr].lv){
if(tree[ll].lsum==tree[ll].len)tree[root].lsum+=tree[rr].lsum;
if(tree[rr].rsum==tree[rr].len)tree[root].rsum+=tree[ll].rsum;
tree[root].sum=max(tree[root].sum,tree[ll].rsum+tree[rr].lsum);
}
} void build(int root,int l,int r){
tree[root].len=r-l+1;//放在里面了。。。错了
if(l==r){
tree[root].init(l,r);
return ;
}
int mid=(l+r)>>1;
build(lson);
build(rson);
pushup(root);
}
void update(int root,int l,int r,int A,int B){
int mid=(l+r)>>1;
if(l==A&&r==A){
tree[root].lv=tree[root].rv=B;
return;
}
if(mid>=A)update(lson,A,B);
else update(rson,A,B);
pushup(root);
} int query(int root,int l,int r,int A,int B){
if(l>=A&&r<=B)return tree[root].sum;
int mid=(l+r)>>1;
int ans=0;
if(mid>=A)ans=max(ans,query(lson,A,B));//多加了return错了半天;;;;
if(mid<B)ans=max(ans,query(rson,A,B));//
if(tree[ll].rv<tree[rr].lv)
ans=max(ans,min(mid-A+1,tree[ll].rsum)+min(B-mid,tree[rr].lsum));
//以免超过查询区间;因为里面的lsum,rsum分别维护的左右最大连续上升序列;
return ans;
}
int main(){
int T,N,M;
char s[5];
int A,B;
SI(T);
while(T--){
SI(N);SI(M);
build(1,1,N);
while(M--){
scanf("%s%d%d",s,&A,&B);
A++;
if(s[0]=='Q'){
B++;
printf("%d\n",query(1,1,N,A,B));
}
else update(1,1,N,A,B);
// print(1,1,N);
}
}
return 0;
}

  

LCIS(线段树区间合并)的更多相关文章

  1. hdu-3308 LCIS (线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  3. hud 3308 LCIS 线段树 区间合并

    题意: Q a b 查询[a, b]区间的最长连续递增子序列的长度 U a b 将下表为a的元素更新为b 区间合并一般都有3个数组:区间最值,左区间最值和右区间最值 具体详见代码 #include & ...

  4. LCIS HDU - 3308 (线段树区间合并)

    LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...

  5. hdu 3308(线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. POJ 3667 Hotel(线段树 区间合并)

    Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...

  7. HDU 3911 线段树区间合并、异或取反操作

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...

  8. HDU 3911 Black And White(线段树区间合并+lazy操作)

    开始以为是水题,结果...... 给你一些只有两种颜色的石头,0为白色,1为黑色. 然后两个操作: 1 l r 将[ l , r ]内的颜色取反 0 l r 计算[ l , r ]内最长连续黑色石头的 ...

  9. HYSBZ 1858 线段树 区间合并

    //Accepted 14560 KB 1532 ms //线段树 区间合并 /* 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[ ...

  10. poj3667 线段树 区间合并

    //Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. Android-Ant自动编译打包android项目 -- 2 ----签名与渠道包

    上篇介绍了怎么使用ant自动编译打包现有的android项目,这篇将继续介绍如果如何在ant打包应用的时候加入签名信息以及自动打包渠道包. 1. 加入签名信息: 在项目的根目录下建一个ant.prop ...

  2. 有趣的keil MDK细节

    1.MDK中的char类型的取值范围是? 在MDK中,默认情况下,char 类型的数据项是无符号的,所以它的取值范围是0-255.它们可以显式地声明为signed char 或 unsigned.因此 ...

  3. ASP.NET缓存中Cache过期的三种策略

    原文:ASP.NET缓存中Cache过期的三种策略 我们在页面上添加三个按钮并双击按钮创建事件处理方法,三个按钮使用不同的过期策略添加ASP.NET缓存. <asp:Button ID=&quo ...

  4. HTML5 服务器发送事件(Server-Sent Events)介绍

    w3cschool菜鸟教程 Server-Sent 事件 - 单向消息传递 Server-Sent 事件指的是网页自动获取来自服务器的更新. 以前也可能做到这一点,前提是网页不得不询问是否有可用的更新 ...

  5. MediaController

    前言 本章内容是android.widget.MediaController,版本为Android 2.3 r1,翻译来自"唐明",再次感谢"唐明" !期待你一 ...

  6. CSS3实战开发 表单发光特效实战开发

    首先,我们先准备好html代码: <!doctype html> <html> <head> <meta charset="utf-8"& ...

  7. api (二) 创建控件 (转)

    在Win32 SDK环境下,怎么来创建常用的那些基本控件呢?我们知道如果用MFC,简单的拖放即可完成大多数控件的创建,但是我们既然是用Windows SDK API编程,当然是从根上解决这个问题,实际 ...

  8. leetcode Swap Nodes in Pairs python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  9. Android minHeight/Width,maxHeight/Width

    在layout文件中,设置IamgeView的最大(最小)高度(宽度)时,需要同时设置android:adjustViewBounds="true",这样设置才会生效.在代码中设置 ...

  10. android:visibility

    RelativeLayout android:visibility="gone/visible/invisible" 此属性意思是此视图是否显示 例如RelativeLayout中 ...