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 ...
随机推荐
- PHP:压缩 Zip
文章来源:http://www.cnblogs.com/hello-tl/p/7661222.html <?php # 文件字符集 header("Content-type: text ...
- 10-看图理解数据结构与算法系列(B+树)
B+树 B+树是B树的一种变体,也属于平衡多路查找树,大体结构与B树相同,包含根节点.内部节点和叶子节点.多用于数据库和操作系统的文件系统中,由于B+树内部节点不保存数据,所以能在内存中存放更多索引, ...
- 使用JS对form的内容验证失败后阻止提交
1.form的两个事件 submit,提交表单,如果直接调用该函数,则直接提交表单 onSubmit,提交按钮点击时先触发,然后触发submit事件.如果不加控制的话,默认返回true,因此表单总能提 ...
- 九度oj 题目1056:最大公约数
题目1056:最大公约数 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8068 解决:5317 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. ...
- 7-14 电话聊天狂人(25 分)(Hash表基本操作)
7-14 电话聊天狂人(25 分) 给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人. 输入格式: 输入首先给出正整数N(≤105),为通话记录条数.随后N行,每行给出一条通话记录.简单 ...
- Chrome new features
Chrome new features copy fetch url fetch("http://10.1.5.202/deploy/http/send/svnuser", { & ...
- idea导入(import)项目和打开(open)项目的区别
前言: 每次接手老项目,都得从git或svn下载下来,但是如果之前的项目不是用idea写的怎么办,可是你又习惯啦idea,那你必须把项目在idea上跑起来,那是用import还是用open呢,如何抉择 ...
- msp430入门编程05
msp430中C语言的运算符和表达式 msp430中C语言的程序结构06 msp430中C语言的函数及实现07 msp430中C语言操作端口I/O10 msp430中C语言的模块化头文件及实现11 m ...
- Letter Combinations of a Phone Number(带for循环的DFS,组合问题,递归总结)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- MongoDB学习day03--索引和explain分析查询速度
一.索引基础 db.user.ensureIndex({"username":1}) 创建索引,username为key,数字 1 表示 username 键的索引按升序存储, - ...