这个是动态的,所以要用线段树维护。代码里有注释因为ls敲成lsum,rs敲成rsum查错查了好久。。

 #include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
template <class T>
inline bool scan_d(T &ret)
{
char c;
int sgn;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&(c<''||c>''))
c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='')
ret=ret*+(c-'');
ret*=sgn;
return ;
} const int maxn = 1e5+;
int ls[maxn<<],rs[maxn<<]; //ls为区间左值,rs为区间右值 比较时要用到。
int lsum[maxn<<],rsum[maxn<<],sum[maxn<<]; //lsum为区间左上升长度,rsum为区间右上升长度,sum为区间最大上升长度。 void push_up(int l,int r,int pos)
{
ls[pos] = ls[pos<<];
rs[pos] = rs[pos<<|];
lsum[pos] = lsum[pos<<];
rsum[pos] = rsum[pos<<|];
sum[pos] = max(sum[pos<<],sum[pos<<|]);
int mid = (l + r) >> ;
if (ls[pos<<|] > rs[pos<<])
{
sum[pos] = max(sum[pos],rsum[pos<<] + lsum[pos<<|]);
if (lsum[pos<<] == mid - l + ) //左区间左上升长度已满
lsum[pos] += lsum[pos<<|];
if (rsum[pos<<|] == r - mid) //同理,
rsum[pos] += rsum[pos<<];
}
} void build (int l,int r,int pos)
{
if (l == r)
{
int tmp;
scanf ("%d",&tmp);
ls[pos] = tmp;
rs[pos] = tmp;
lsum[pos] = rsum[pos] = sum[pos] = ;
return;
}
int mid =(l + r) >> ;
build(l,mid,pos<<);
build(mid+,r,pos<<|);
push_up(l,r,pos);
} void update(int l,int r,int pos,int x,int val)
{
if (l == r)
{
ls[pos] = rs[pos] = val;
return;
}
int mid = (l + r) >> ;
if (x <= mid)
update(l,mid,pos<<,x,val);
else
update(mid+,r,pos<<|,x,val);
push_up(l,r,pos);
} int query(int l,int r,int pos,int ua,int ub)
{
if (ua <= l && ub >= r)
{
return sum[pos];
}
int mid = (l + r) >> ;
int ans1 = ,ans2 = ,ans3 = ;
if (ua <= mid)
ans1 = query(l,mid,pos<<,ua,ub);
if (ub > mid)
ans2 = query(mid+,r,pos<<|,ua,ub);
if (ls[pos<<|] > rs[pos<<])
ans3 = min(lsum[pos<<|],ub-mid) + min(rsum[pos<<],mid-ua+);
return max(ans1,max(ans2,ans3));
} int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int t;
cin>>t;
while (t--)
{
int n,q;
scanf ("%d%d",&n,&q);
build(,n,);
char op[];
int x,y;
for (int i = ; i < q; i++)
{
scanf ("%s%d%d",op,&x,&y);
if (op[] == 'Q')
printf("%d\n",query(,n,,x+,y+));
if (op[] == 'U')
update(,n,,x+,y);
}
}
return ;
}

hdu3308--LCIS 最大连续递增序列长度的更多相关文章

  1. LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  2. [Swift]LeetCode674. 最长连续递增序列 | Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...

  3. LeetCode 最长连续递增序列

    给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...

  4. LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...

  5. leetcode 674. 最长连续递增序列

    1. 题目 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3, ...

  6. LeetCode 674. 最长连续递增序列(Longest Continuous Increasing Subsequence) 18

    674. 最长连续递增序列 674. Longest Continuous Increasing Subsequence 题目描述 给定一个未经排序的整型数组,找到最长且连续的递增序列. Given ...

  7. Leetcode674.Longest Continuous Increasing Subsequence最长连续递增序列

    给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...

  8. Java实现 LeetCode 674 最长连续递增序列(暴力)

    674. 最长连续递增序列 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. ...

  9. C#LeetCode刷题之#674-最长连续递增序列( Longest Continuous Increasing Subsequence)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3734 访问. 给定一个未经排序的整数数组,找到最长且连续的的递增 ...

随机推荐

  1. SQL Server 系统时间

    getdate()函数:取得系统当前的日期和时间.返回值为datetime类型的. 用法:getdate() 例子: select getdate() as dte,dateadd(day,-1,ge ...

  2. Android邮件发送详解

    转载:http://flysnow.iteye.com/blog/1128354 Android中我为什么发不了邮件???我手机里明明有邮件客户端的,可我为什么不能调用它发送邮件???相信这是很多人会 ...

  3. 安装orcle10g oel5.6

    一.安装OEL 5.6 二.安装VMware Tools 1)  选择菜单里的VM选项,里面有一个子选项是installVMware Tools,选择它. 2)   回到操作系统,将光驱挂载到/mnt ...

  4. 最好的Laravel中文文档

    分页 配置 基本用法 给分页链接添加自定义信息 配置 在其它的框架中,分页有时很痛苦. 但是Laravel让分页简单到不可思议. 默认Laravel包含了两个分页视图, 在app/config/vie ...

  5. linux 下文件的比较

    1.cmp命令,比较两个文件是否相同 比较文件test1和test2,如果这两个文件完全相同,则无任何输出,否则,输出第一处不同所在的字节以及行号,然后忽略后面的不同之处,退出命令的执行. [root ...

  6. 解决VS2008闪退的问题

    问题:打开VS2008项目后,应该是加载完所有文件,立即断掉了IDE,查看事件器,发现图片中的错误描述,google了很久没有找到解决方案,后来还是自己动手解决这个问题花了一早上的时间,哎,只要把工程 ...

  7. C#字符串的比较

    Console.WriteLine("输入字符1"); string n1 = Console.ReadLine(); Console.WriteLine("输入字符2& ...

  8. ios app开发步骤

    虽然开发一个app的任务看上去可能很艰巨,但是整个过程可以抽象成几个相对简单的步骤,下面这些步骤会在你开发第一个app时帮你步入正途. 定义Concept 每个好app都是从一个concept开始. ...

  9. c3p0写连接池 Demo

    1.导包 2.配置文件:名称必须为:c3p0-config.xml,且必须放在src根目录下 <c3p0-config> <!-- 默认配置,有且仅可出现一次 ,如果没有指定则使用这 ...

  10. .net framework3.0 以上版本开发的软件乱码问题

    首先介绍一下:WPF是微软新一代图形系统,运行在.NET Framework 3.0及以上版本下,为用户界面.2D/3D 图形.文档和媒体提供了统一的描述和操作方法.基于DirectX 9/10技术的 ...