HDU 3308 LCIS (线段树·单点更新·区间合并)
题意 给你一个数组 有更新值和查询两种操作 对于每次查询 输出相应区间的最长连续递增子序列的长度
基础的线段树区间合并 线段树维护三个值 相应区间的LCIS长度(lcis) 相应区间以左端点为起点的LCIS长度(lle) 相应区间以右端点为终点的LCIS长度(lri) 然后用val存储数组相应位置的值 当val[mid + 1] > val[mid] 的时候就要进行区间合并操作了
#include <cstdio>
#include <algorithm>
#define lc lp, s, mid
#define rc rp, mid+1, e
#define lp p<<1
#define rp p<<1|1
#define mid ((s+e)>>1)
using namespace std;
const int N = 100005, M = N * 4;
int lcis[M], lle[M], lri[M], val[N]; void pushup(int p, int s, int e)
{
lcis[p] = max(lcis[lp], lcis[rp]);
lle[p] = lle[lp], lri[p] = lri[rp];
if(val[mid + 1] > val[mid]) //合并条件
{
lcis[p] = max(lcis[p], lri[lp] + lle[rp]);
if(lle[lp] == mid + 1 - s) lle[p] += lle[rp];
if(lri[rp] == e - mid) lri[p] += lri[lp];
}
} void build(int p, int s, int e)
{
if(s == e)
{
lcis[p] = lle[p] = lri[p] = 1;
scanf("%d", &val[s]);
return;
}
build(lc);
build(rc);
pushup(p, s, e);
} void update(int p, int s, int e, int x, int v)
{
if(s == e)
{
val[s] = v;
return;
}
if(x <= mid) update(lc, x, v);
else if(x > mid) update(rc, x, v);
pushup(p, s, e);
} int query(int p, int s, int e, int l, int r)
{
if(l <= s && e <= r) return lcis[p];
int ret = 0;
if(val[mid + 1] > val[mid])
ret = min(r, mid + lle[rp]) - max(l, mid + 1 - lri[lp]) + 1;
if(l <= mid) ret = max(ret, query(lc, l, r));
if(r > mid) ret = max(ret, query(rc, l, r));
return ret;
} int main()
{
int T, n, m, a, b;
char op[5];
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
build(1, 0, n - 1);
while(m--)
{
scanf("%s%d%d", op, &a, &b);
if(op[0] == 'Q')
printf("%d\n", query(1, 0, n - 1, a, b));
else update(1, 0, n - 1, a, b);
}
}
return 0;
}
LCIS
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).
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
1
1
4
2
3
1
2
5
HDU 3308 LCIS (线段树·单点更新·区间合并)的更多相关文章
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- POJ 2892 Tunnel Warfare(线段树单点更新区间合并)
Tunnel Warfare Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 7876 Accepted: 3259 D ...
- hdu1540之线段树单点更新+区间合并
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 5316 Magician(2015多校第三场第1题)线段树单点更新+区间合并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5316 题意:给你n个点,m个操作,每次操作有3个整数t,a,b,t表示操作类型,当t=1时讲a点的值改 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 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 ...
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
随机推荐
- 刷题总结——做运动(NOIP模拟)
题目: 给定一个无向图,节点数n<=50000,m<=1000000,每条边有两个值t和c,边的长度为t*c···现在要求再t尽量小的情况下,求两节点st的最短距离 题解: 第一次做的时候 ...
- gulpfile.js备份
var gulp = require('gulp'); var uglify = require('gulp-uglify'); // var rename = require('gulp-renam ...
- bzoj 3924 幻想乡战略游戏
题目大意: 有边权点权的树,动态修改点权 每次修改后求带权重心x (\(minimize\) \(S=\sum_i val[i]*dist[x][i]\)) 分析: 从暴力找突破口: 对于边x,y,设 ...
- 【NOIP2016练习】T1 挖金矿(二分答案)
题意: 思路:二分答案A 合法的答案 sigma(s[i][xi])/sigma(xi)>=a i<=m sigma(s[i][xi]-a*xi)>=0 对于每个i找到xi使s[i] ...
- 应用defineProperty简单实现vue的双向数据绑定
双向数据绑定简易版本如何应用defineProperty的getter setter 方法 有这样HTML片段 <input type="text" id="dem ...
- 反汇编->C++内联
C/C++提供了内联函数机制 内联函数就是向编译器建议:编译这个函数的时候.直接把函数展开,而不是进行函数调用call.当然编译器并不接受这个建议.仍然把他当做普通函数进行编译 使用内联函数的优点:减 ...
- LeetCode OJ--Permutations *
https://oj.leetcode.com/problems/permutations/ 写出一列数的全排列 #include <iostream> #include <vect ...
- Codeforces 246E Blood Cousins Return(树上启发式合并)
题目链接 Blood Cousins Return #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) f ...
- OpenLDAP给我的启发
首先这篇文章没什么技术性,但亮点是:我会给广大运维同行提一点建议,这个一点仅仅是一点,而不是很多点. 年前计划深度掌握一些诸如:Jenkins.Gitlab.ELK.k8s等的软件,但学着学着总是想学 ...
- Oracle SOA Suite OverView
SOA是一场架构的变革,那既然是变革,那就一定是有内在的原因来推动这个架构的变革.在过去几十年的时间里面,应用程序架构已经经历了3次巨大的变革,从Terminal/主机--> Client/Se ...