这个是动态的,所以要用线段树维护。代码里有注释因为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. 基准测试之netperf

    使用 server端 [root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/netperf] #netserver -p 10001 Starti ...

  2. JAVA的四种引用,强弱软虚用到的场景

    1.强引用 最常用的引用类型,如Object object = new Object(),只要强引用存在,GC必定 不回收,即使当前内存空间不足,jAVA虚拟机宁愿抛出OutofMemoryError ...

  3. Spring的StringUtils工具类

    本文是转载文章,感觉比较好,如有侵权,请联系本人,我将及时删除. 原文网址:<Spring的StringUtils工具类> org.springframework.util.StringU ...

  4. CSS常用操作-图片

    index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  5. mongodb授权登录

    mongodb版本为3.2(目前最新),演示的是linux下的mongodb授权认证 第一次登录不启动授权(mongo默认不启动) ./mongod --dbpath=/home/db/data -- ...

  6. UUID.randomUUID()方法介绍

    UUID.randomUUID().toString()是javaJDK提供的一个自动生成主键的方法.UUID(Universally Unique Identifier)全局唯一标识符,是指在一台机 ...

  7. Adobe/Flash Media Server 5.0 linux 64位系统下的安装

    一.下载 Adobe/Flash MS5.0下载地址: http://fs1.d-h.st/download/00036/VOt/adobemediaserver_5_ls1_linux64.tar. ...

  8. C++沉思录之一

    一.系统跟踪类Trace的设计过程: step1:简单版 class Trace { public: Trace() { noisy = ; } void print(char* s) { if(no ...

  9. Aspose.Cells for .NET 8.5.0 工具类

    基于 Aspose.Cells for .NET 8.5.0 工具类, Aspose.Cells for .NET 8.5.0 这个自己去CSDN下载里面有破解的,没有破解的导出excel的时候会(A ...

  10. shell获取日期(昨天,明天,上月,下月)

    今天 sh-4.1$ echo `date +%Y-%m-%d` 2016-08-17 昨天 sh-4.1$ echo `date -d "last day" +%Y-%m-%d` ...