hdu3308--LCIS 最大连续递增序列长度
这个是动态的,所以要用线段树维护。代码里有注释因为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 最大连续递增序列长度的更多相关文章
- LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- [Swift]LeetCode674. 最长连续递增序列 | Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...
- LeetCode 最长连续递增序列
给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...
- LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...
- leetcode 674. 最长连续递增序列
1. 题目 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3, ...
- LeetCode 674. 最长连续递增序列(Longest Continuous Increasing Subsequence) 18
674. 最长连续递增序列 674. Longest Continuous Increasing Subsequence 题目描述 给定一个未经排序的整型数组,找到最长且连续的递增序列. Given ...
- Leetcode674.Longest Continuous Increasing Subsequence最长连续递增序列
给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...
- Java实现 LeetCode 674 最长连续递增序列(暴力)
674. 最长连续递增序列 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. ...
- C#LeetCode刷题之#674-最长连续递增序列( Longest Continuous Increasing Subsequence)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3734 访问. 给定一个未经排序的整数数组,找到最长且连续的的递增 ...
随机推荐
- Ajax解析
1.Ajax Asynchronous(异步的) javascript and xml 技术组成: CSS + xml +JavaScript +DOM Ajax核心对象: XmlHttpReques ...
- 【C#基础】HTTP发送POST二进制数据
//postdata为数组的请求方式 public byte[] POST(string Url, byte[] byteRequest) { byte[] responsebody; HttpWeb ...
- Lance老师UI系列教程第八课->新浪新闻SlidingMenu界面的实现
UI系列教程第八课:Lance老师UI系列教程第八课->新浪新闻SlidingMenu界面的实现 今天蓝老师要讲的是关于新浪新闻侧滑界面的实现.先看看原图: 如图所示,这种侧滑效果以另一种方式替 ...
- oracle tkprof 工具详解
oracle tkprof 工具详解 今天是2013-09-26,进行tkprof工具使用学习,在此记录一下笔记: 一)查看需要跟踪会话信息: select s.sid,s.serial#,s.us ...
- [RxJS] Observables can throw errors
Whenever we are writing code, we need to remember that things may go wrong. If an error happens in a ...
- vmstat
vmstat(virtual memory statitics)命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况, ...
- debug连线指令
-當發現原本正常的連線突然斷線的,請用底下的指令debug 1.ifconfig (看看IPaddress) 2.wpa_clira stat (看看連線狀態) 3.如果是在連線中(wp ...
- sass基础学习
2015.6.281.安装ruby2.运行gem安装sass-->gem install sass3.编译命令行sass --watch 文件路径/test.scss:编译后文件路径/test. ...
- jquery1.9学习笔记 之层级选择器(二)
子孙选择器(“祖先 子孙”) 描述:选择所有给出祖先选择器的子孙选择器. 例子: 用蓝色虚线边框标记所有表单子孙元素的输入.表单里的输入框用黄色背景. <!doctype html>< ...
- MySQL 查询结果保存为CSV文件
MySQL支持将查询结果直接导出为文本格式,格式如下: into outfile '导出的目录和文件名' 指定导出的目录和文件名 fields terminated ...