hdu 3308 线段树
题目大意:给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 线段树的更多相关文章
- hdu 3308(线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 3308 线段树单点更新+区间查找最长连续子序列
LCIS Time Limit: 6000/2000 MS (Java/Oth ...
- HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询
题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...
- hdu 3308 线段树 区间合并+单点更新+区间查询
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 3308 线段树求区间最长连续上升子序列长度
题意:两种操作,Q L R查询L - R 的最长连续上升子序列长度,U pos val 单点修改值 #include <bits/stdc++.h> #define N 100005 us ...
- hdu 3308 线段树,单点更新 求最长连续上升序列长度
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 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 ...
- hdu 3974 线段树 将树弄到区间上
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3436 线段树 一顿操作
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
随机推荐
- python模块-platform
#author:Blood_Zero #coding:utf- import platform print dir(platform) #获取platform函数功能 platform.archite ...
- 【Eclipse】eclipse生成类图、类交互图、包依赖图
今天,在修改毕设论文的时候需要画类图,系统已经开发完成,如果手动拿PowerDesigner画类图太浪费时间,于是通过网上查阅资料发现eclipse可以集成一个插件生成类图,也可以生成包图.现在做记录 ...
- C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉
为了提高httpwebrequest的执行效率,查到了一些如下设置 request.ServicePoint.Expect100Continue = false; request.ServicePoi ...
- linux用户权限 -> 系统特殊权限
set_uid 运行一个命令的时候,相当于这个命令的所有者,而不是执行者的身份. suid的授权方法 suid 权限字符s(S),用户位置上的x位上设置. 授权方法: passwd chmod u+s ...
- Flask:操作SQLite3(0.1)
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 本文介绍了第一次在Flask框架中操作SQLite3数据库的测试,参考了官网的文档Using SQLite 3 wit ...
- sld一张图
- Oracle 函数 “申请通过后,将该表中循环遍历到的所有内容插到另一个表中”
create or replace function mcode_apply_insert_material(p_mca_no VARCHAR2, p_action VARCHAR2, p_wf_no ...
- pom.xml一个简单配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- MySQL学习笔记:coalesce
函数:coalesce 作用:返回传入的参数中第一个非NULL的值 ); # ); # 如果传入的参数所有都是NULL,则返回NULL,比如: SELECT COALESCE(NULL, NULL, ...
- vuejs学习--递归组件(树型表格分享)
前言 学习vue有一段时间了,最近使用vue做了一套后台管理系统,其中使用最多就是递归组件,也因为自己对官方文档的不熟悉使得自己踩了不少坑,今天写出来和大家一起分享. 递归组件 组件在它的模板内可以递 ...