LCIS

                                                             Time Limit: 6000/2000 MS (Java/Others)    

                                                            Memory Limit: 65536/32768 K (Java/Others)
                                                            Total Submission(s): 5591    Accepted Submission(s): 2443

Problem Description
Given n integers.
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].
 
Input
T in the first line, indicating the case number.
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).
 
Output
For each Q, output the answer.
 
Sample Input
1
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
 
Sample Output
1
1
4
2
3
1
2
5
 
Author
shǎ崽
 
题解:开始看错题,以为是最长子序列,GG,
  后知后觉,线段树秒了
///
#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 线段树单点更新+区间查找最长连续子序列的更多相关文章

  1. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  3. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  4. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  5. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  6. hdu2795(线段树单点更新&区间最值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...

  7. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  8. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. hdu 1754 I Hate It 线段树 单点更新 区间最值

    线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...

随机推荐

  1. UML系统建模学习

    什么是UML系统建模 UML系统建模是一种与面向对象软件开发密切相关的建模方法.通过建造模型可以验证建造事物的可行性.UML是一种统一建模语言,它的全称是(Unified Method Languag ...

  2. MySQL 快速入门教程

    转:MySQL快速 入门教程 目录 一.MySQL的相关概念介绍 二.Windows下MySQL的配置 配置步骤 MySQL服务的启动.停止与卸载 三.MySQL脚本的基本组成 四.MySQL中的数据 ...

  3. 集训第六周 M题

    Description   During the early stages of the Manhattan Project, the dangers of the new radioctive ma ...

  4. 一个IT工薪族的4年奋斗成果

     关于标题:为了方便传播,使用了"最简化"的一段. 过段时间,考虑改为"大学毕业4年-回顾和总结(11):一个IT工薪族的4年奋斗成果(2012年6月17日~2016年6 ...

  5. Qt5笔记之数据库(五)SQL表格模型QSqlTableModel

    教程网址:http://www.qter.org/portal.php?mod=view&aid=57 0.打开tablemodel.pro文件,加上: QT += coregui sql 注 ...

  6. 如何实现IIS 7.0对非HTTP协议的支持

    在<再谈IIS与ASP.NET管道>介绍各种版本的IIS的设计时,我们谈到IIS 7.0因引入WAS提供了对非HTTP协议的支持.这个对于WCF的服务寄宿来说意义重大,它意味着我们通过II ...

  7. CentOS7 Firewall防火墙配置用法详解

    centos 7中防火墙是一个非常的强大的功能了,但对于centos 7中在防火墙中进行了升级了,下面我们一起来详细的看看关于centos 7中防火墙使用方法.   FirewallD 提供了支持网络 ...

  8. Codeforces Round #261 (Div. 2) E (DP)

    E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do hi ...

  9. android 上AES解密是报错javax.crypto.BadPaddingException: pad block corrupted

    网上看到两种方法: 1.SecretKeySpec skeySpec = new SecretKeySpec(getRawKey(key), "AES"); private sta ...

  10. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...