这个是动态的,所以要用线段树维护。代码里有注释因为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. iOS socket 实现tcp和服务器长链接的简单使用心得

    首先iOS端用了一个第三方的框架 GCDAsyncSocket 当然这个是CocoaAsyncSocket框架里面的一部分 Github下载地址https://github.com/robbiehan ...

  2. JAXB--学习1

    一.简介 JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实 ...

  3. Android adb

    查看原文:http://blog.csdn.net/u010818425/article/details/52266593 (一)基础操作 安装app adb install -r xxx.apk / ...

  4. android .9.png ”点九” 图片制作方法

    “点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png 智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向, ...

  5. 基于mapreducer的图算法

    作者现就职阿里巴巴集团1688技术部 引言 周末看到一篇不错的文章"Graph Twiddling in a MapReduce world" ,介绍MapReduce下一些图算法 ...

  6. (3)选择元素——(15)总结(Summary)

    With the techniques that we have covered in this chapter, we should now be able to locate sets of el ...

  7. Android TextView属性

    android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/all)android:a ...

  8. Java基础知识强化45:StringBuffer类之字符串反转的案例

    1. 案例演示: package cn.itcast_07; import java.util.Scanner; /* * 把字符串反转 */ public class StringBufferTes ...

  9. Linux常用命令之 查找命令 find —— 细说 -atime,-mtime,-ctime

    我们知道 Linux里面一切皆文件 ,那么我们能否查看一个文件是何时创建的呢?答案是否定的.那我们可以知道些文件关于时间的什么信息呢?那就不得不说文件状态的三个时间了,它们分别是 -atime, -c ...

  10. C#。4.1数组的应用

    数组的应用 (一).冒泡排序.1.冒泡排序是用双层循环解决.外层循环的是趟数,里层循环的是次数.2.趟数=n-1:次数=n-趟数.3.里层循环使用if比较相临的两个数的大小,进行数值交换. 代码 in ...