题目大意:给n个数,两种操作1:U  a b   更新第a个为b (从0开始)
2: Q    a ,b  查询 a,b之间LCIS(最长连续递增子序列)的长度。

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

 #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 100005
using namespace std; int mlen[maxn<<],lmlen[maxn<<],rmlen[maxn<<];
int num[maxn]; void pushup(int rt,int l,int r)
{
lmlen[rt]=lmlen[rt<<];
rmlen[rt]=rmlen[rt<<|];
mlen[rt]=max(mlen[rt<<],mlen[rt<<|]);
int mid=(l+r)>>;
int m=(r-l)+;
if(num[mid]<num[mid+]) //左区间的右值小于右区间的左值可以合并
{
if(lmlen[rt]==m-(m>>)) lmlen[rt]+=lmlen[rt<<|];
if(rmlen[rt]==(m>>)) rmlen[rt]+=rmlen[rt<<];
mlen[rt]=max(mlen[rt],lmlen[rt<<|]+rmlen[rt<<]);
}
}
void build(int l,int r,int rt)
{
if(l==r)
{
mlen[rt]=lmlen[rt]=rmlen[rt]=;
return ;
}
int m=(l+r)>>;
build(lson);
build(rson);
pushup(rt,l,r);
}
void update(int a,int l,int r,int rt)
{
if(l==r)
{
return;
}
int m=(l+r)>>;
if(a<=m) update(a,lson);
else update(a,rson);
pushup(rt,l,r);
} int query(int L,int R,int l,int r,int rt)
{
//printf("%d %d %d %d %d\n",L,R,l,r,rt);
if(L<=l&&r<=R)
{
return mlen[rt];
}
int m=(l+r)>>;
if(R<=m) return query(L,R,lson); //与一般不同,不能是子集,只能全部属于才能直接查询子区间 返回子区间的mlen
if(L>m) return query(L,R,rson); //否则是确认儿子区间是否能合并,并在三者之间取最大值 int ta,tb;
ta=query(L,R,lson);
tb=query(L,R,rson);
int ans;
ans=max(ta,tb);
if(num[m]<num[m+]) //同上
{
int temp;
temp=min(rmlen[rt<<],m-L+)+min(lmlen[rt<<|],R-m);
ans=max(temp,ans);
}
return ans;
} int main()
{
int T,n,m;
int i,j;
char f[];
int a,b;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&T);
for(i=;i<T;i++)
{
scanf("%d %d",&n,&m);
for(j=;j<=n;j++)
scanf("%d",&num[j]);
build(,n,);
while(m--)
{
scanf("%s",&f);
if(f[]=='U')
{
scanf("%d %d",&a,&b);
a++;
num[a]=b;
update(a,,n,);
}
else
{
scanf("%d %d",&a,&b);
a++,b++;
printf("%d\n",query(a,b,,n,));
}
}
}
return ;
}

hdu 3308 线段树的更多相关文章

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

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

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

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

  3. HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询

    题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...

  4. hdu 3308 线段树 区间合并+单点更新+区间查询

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

  5. HDU 3308 线段树求区间最长连续上升子序列长度

    题意:两种操作,Q L R查询L - R 的最长连续上升子序列长度,U pos val 单点修改值 #include <bits/stdc++.h> #define N 100005 us ...

  6. hdu 3308 线段树,单点更新 求最长连续上升序列长度

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

  7. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  8. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

随机推荐

  1. 08 Packages 包

    Packages   Standard library Other packages Sub-repositories Community Standard library Name Synopsis ...

  2. go 切片的 插入、删除

    package main import ( "fmt" ) func InsertSpringSliceCopy(slice, insertion []string, index ...

  3. CentOS/Linux 网卡设置 IP地址配置

    CentOS/Linux下设置IP地址 1:临时修改:1.1:修改IP地址# ifconfig eth0 192.168.100.100 1.2:修改网关地址# route add default g ...

  4. JavaSE简单实现多线程聊天

    1.1 主程序入口 在主程序入口处,通过设置MyWindow的第一个参数,如果为true则为服务器,如果为false,则为客户端,当然也可以设置第二个参数,区分客户端和服务器的窗口标题. public ...

  5. JS正则表达式方法

    使用正则表达式的主要有match,exec,test 1.正则表达式方法test测试给定的字符串是否满足正则表达式,返回值是bool类型的,只有真和假. var user_code = $(" ...

  6. 20165203 实验二 Java面向对象程序设计

    20165203 实验二 Java面向对象程序设计 一.面向对象程序设计1--单元测试和TDD 1.实验要求 参考 (http://www.cnblogs.com/rocedu/p/6371315.h ...

  7. Ansible之迭代、模板

    本节内容: 迭代 模板(JInjia2相关) Jinja2相关 一.迭代 当有需要重复性执行的任务时,可以使用迭代机制.其使用格式为将需要迭代的内容定义为item变量引用,并通过with_items语 ...

  8. nullptr

    以前都是用0来表示空指针的,但由于0可以被隐式类型转换为整形,这就会存在一些问题.关键字nullptr是std::nullptr_t类型的值,用来指代空指针.nullptr和任何指针类型以及类成员指针 ...

  9. 【LOJ】#2306. 「NOI2017」蔬菜

    题解 从后往前递推 如果我们知道了第i天的最优方案和第i天选择的蔬菜,加入第i天选择的蔬菜数量为S,我们只需要减去最小的S - (i - 1) * M 个蔬菜即可 所以我们只要求出最后一天的蔬菜选择 ...

  10. tp5总结(四)

    数据库 1.数据库配置 1-1.配置文件配置[http://ww:7070/tp5-3/public/] 1-2.Db::connect配置[数组和字符串方式][http://ww:7070/tp5- ...