HDU 3308 线段树单点更新+区间查找最长连续子序列
LCIS
Time Limit: 6000/2000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5591 Accepted Submission(s): 2443
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
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
1
4
2
3
1
2
5
///
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a))
#define memfy(a) memset(a,-1,sizeof(a))
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b) scanf("%d%d",&a,&b)
#define mod 1000000007
#define inf 1000000001
#define maxn 200000+2
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
struct ss
{
int l,r,v,ans;
int lc,rc;
}tr[maxn<<];
int a[maxn<<],n,q;
void push_up(int k)
{
if(a[tr[k<<].r]<a[tr[k<<|].l])
{
tr[k].ans=max(max(tr[k<<].ans,tr[k<<|].ans),tr[k<<].rc+tr[k<<|].lc);
if(tr[k<<].lc==(tr[k<<].r-tr[k<<].l+))
{
tr[k].lc=tr[k<<].lc+tr[k<<|].lc;
}else tr[k].lc=tr[k<<].lc;
if(tr[k<<|].lc==(tr[k<<|].r-tr[k<<|].l+))
{
tr[k].rc=tr[k<<|].rc+tr[k<<].rc;
}else tr[k].rc=tr[k<<|].rc;
}
else
{
tr[k].ans=max(tr[k<<].ans,tr[k<<|].ans);
tr[k].lc=tr[k<<].lc;
tr[k].rc=tr[k<<|].rc;
}
}
void build(int k,int s,int t)
{
tr[k].l=s;
tr[k].r=t;
if(s==t)
{
tr[k].v=a[s];
tr[k].ans=;
tr[k].lc=;
tr[k].rc=;
return ;
}
int mid=(s+t)>>;
build(k<<,s,mid);
build(k<<|,mid+,t);
push_up(k);
}
void update(int k,int x,int c)
{
if(tr[k].l==x&&tr[k].r==x)
{
tr[k].v=c;
a[x]=c;
return ;
}
int mid=(tr[k].l+tr[k].r)>>;
if(x<=mid)update(k<<,x,c);
else update(k<<|,x,c);
push_up(k);
}
int ask(int k,int s,int t)
{
if(tr[k].l==s&&tr[k].r==t)
{
return tr[k].ans;
}
int mid=(tr[k].l+tr[k].r)>>;
if(t<=mid)return ask(k<<,s,t);
else if(s>mid)return ask(k<<|,s,t);
else {
int ret=;
int A=ask(k<<,s,mid);
int B=ask(k<<|,mid+,t);
ret=max(A,B);
A=min(tr[k<<].rc,mid-s+);
B=min(tr[k<<|].lc,t-mid);
if(a[tr[k<<].r]<a[tr[k<<|].l])
ret=max(A+B,ret);
return ret;
}
}
int main()
{ int T=read();
while(T--)
{
n=read();
q=read();
FOR(i,,n)
{
a[i]=read();
}
build(,,n);
int a,b;
char ch[];
FOR(i,,q)
{
scanf("%s%d%d",ch,&a,&b);
if(ch[]=='Q')
{
printf("%d\n",ask(,a+,b+));
}
else update(,a+,b);
}
}
return ;
}
代码
HDU 3308 线段树单点更新+区间查找最长连续子序列的更多相关文章
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- hdu1166(线段树单点更新&区间求和模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...
- hdu2795(线段树单点更新&区间最值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- 【HDU】1754 I hate it ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1754 I Hate It 线段树 单点更新 区间最值
线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...
随机推荐
- hdfs深入:06、hdfs的写入过程
7.HDFS的文件写入过程 详细步骤解析: 1. client发起文件上传请求,通过RPC与NameNode建立通讯,NameNode检查目标文件是否已存在,父目录是否存在,返回是否可以上传: 2. ...
- Json Web Token(JWT)详解
什么是Json Web Token Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的 ...
- NOIP专题复习3 图论-强连通分量
目录 一.知识概述 二.典型例题 1.[HAOI2006]受欢迎的牛 2.校园网络[[USACO]Network of Schools加强版] 三.算法分析 (一)Tarjan算法 (二)解决问题 四 ...
- <Redis> 入门六 主从复制方式的集群
1.集群如何操作 现在有三台虚拟机,ip分别为100,105,106,将100作为master,其他两台作为slave 1.vim redis.conf 以前的版本是 slaveof <mast ...
- 零基础入门学习Python(25)--字典:当索引不好用时
知识点 字典属于映射类型. 列表,元祖,字符串等属于序列类型 创建及访问字典 #创建一个字典 >>> dict1 = {'李宁':'一切皆有可能','耐克':'Just do it' ...
- cookie和session的区别及session的生命周期
这些都是基础知识,不过有必要做深入了解.先简单介绍一下. 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择,都纪录 ...
- python中正则表达式与模式匹配
一.前言 在之前找工作过程中,面试时经常被问到会不会python,懂不懂正则表达式.心里想:软件的东西和芯片设计有什么关系?咱也不知道因为啥用这个,咱也不敢问啊!在网上搜索到了一篇关于脚本在ASIC领 ...
- table JS合并单元格
function _w_table_rowspan(_w_table_id,_w_table_colnum){ _w_table_firsttd = ""; _w_table_cu ...
- C++动态申请内存 new T()与new T[]的区别
new与delete 我们知道,new和delete运算符是用于动态分配和撤销内存的运算符. new的用法 开辟单变量地址空间: i. 如 new int ; 指开辟一个存放数组的存储空间,返回一个指 ...
- 19-看图理解数据结构与算法系列(Radix树)
Radix树 Radix树,即基数树,也称压缩前缀树,是一种提供key-value存储查找的数据结构.与Trie不同的是,它对Trie树进行了空间优化,只有一个子节点的中间节点将被压缩.同样的,Rad ...