题意:单点更新,区间LCIS(最长连续递增序列)查询。具备区间合并维护的性质,不用线段树用什么~

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define Rep(a, b) for(int a = 0; a < b; a++)
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {} typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef multiset<int>::iterator msii;
typedef set<int> si;
typedef set<int>::iterator sii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {, -, , , -, , , -};
const int maxn = 1e5 + ;
const int maxm = 1e5 + ;
const int maxv = 1e7 + ;
const int MD = 1e9 +;
const int INF = 1e9 + ;
const double PI = acos(-1.0);
const double eps = 1e-; int A[maxn]; struct SegTree {
struct Node {
int suflen, prelen, len;
} tree[maxn << ]; Node merge(Node a, Node b, int l, int m, int r) {
Node c;
int leftLen = m - l + , rightLen = r - m;
c.prelen = a.prelen;
if (c.prelen == leftLen && A[m] < A[m + ]) c.prelen += b.prelen;
c.suflen = b.suflen;
if (c.suflen == rightLen && A[m] < A[m + ]) c.suflen += a.suflen;
c.len = a.len;
c.len = max(c.len, b.len);
if (A[m] < A[m + ])c.len = max(c.len, a.suflen + b.prelen);
return c;
}
void build(int l, int r, int rt) {
if (l == r) {
int x;
scanf("%d", &x);
A[l] = x;
tree[rt].len = tree[rt].prelen = tree[rt].suflen = ;
return ;
}
define_m;
build(lson);
build(rson);
tree[rt] = merge(tree[rt << ], tree[rt << | ], l, m, r);
}
void update(int p, int x, int l, int r, int rt) {
if (l == r) {
tree[rt].len = tree[rt].prelen = tree[rt].suflen = ;
A[l] = x;
return ;
}
define_m;
if (p <= m) update(p, x, lson);
else update(p, x, rson);
tree[rt] = merge(tree[rt << ], tree[rt << | ], l, m, r);
}
Node query(int L, int R, int l, int r, int rt) {
if (L <= l && r <= R) return tree[rt];
define_m;
if (R <= m) return query(L, R, lson);
if (L > m) return query(L, R, rson);
return merge(query(L, m, lson), query(m + , R, rson), L, m, R);
}
}; SegTree st; int main() {
//freopen("in.txt", "r", stdin);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
st.build(, n, );
for (int i = , u, v; i < m; i++) {
char s[];
scanf("%s%d%d", s, &u, &v);
if (s[] == 'U') {
st.update(++u, v, , n, );
}
else {
printf("%d\n", st.query(++u, ++v, , n, ).len);
}
}
}
return ;
}

[hdu3308]线段树的更多相关文章

  1. LCIS hdu3308 (线段树 区间合并)

    题意: 有两种操作  一种是单点改为b  一种是给出区间ab  区间ab的最大上升子序列个数.. 线段树目前学了三种  第一种单点操作很简单   第二种区域操作加上懒惰标记即可 现在这种 为区间合并. ...

  2. HDU3308 线段树(区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. HDU3308 线段树区间合并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 ,简单的线段树区间合并. 线段树的区间合并:一般是要求求最长连续区间,在PushUp()函数中实 ...

  4. hdu3308 线段树 区间合并

    给n个数字 U表示第A个数改为B.A是从0开始. Q输出最大的递增序列个数. 考虑左边,右边,和最大的. #include<stdio.h> #define lson l,m,rt< ...

  5. hdu3308 线段树——区间合并

    更新一个点: 求某个区间的最长连续上升序列: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 #include <cstdio> #in ...

  6. hdu-3308 LCIS (线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. HDU3308(LCIS) 线段树好题

    题目链接:传送门 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y   2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 题目思路: ...

  8. 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)

    转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...

  9. [转载]完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...

随机推荐

  1. [bilibili服]明日方舟游戏时长限制破解

    bilibili服 明日方舟 游戏时长如何破解 众所周知,明日方舟游戏对未成年人实行了游戏时长限制,小编也感到十分惊讶--咳咳--言归正传--之前在网上看到过有说可以通过进入战斗之后断网来实现延长时间 ...

  2. 为什么选择python?

    Why python? 那些最好的程序员不是为了得到更高的薪水或者得到公众的仰慕而编程,他们只是觉得这是一件有趣的事情. —— Linux 之父 Linux Torvalds 作为一个使用主义的学习者 ...

  3. 初探Redis-基础类型String

    Redis存在五种基础类型:字符串(String).队列(List).哈希(Hash).集合(Set).有序集合(Sorted Set).String的出镜率算是最高的.本次列举出String的常用操 ...

  4. HTML+CSS教程(五)外联样式、组选择器、圆角边框、样式优先级、伪类、盒子模型、元素溢出

    一.外联样式 通过link标签引入外部css文件夹中的xxx.css文件到head标签中 例: 二. 1.组选择器 选择器名称1,选择器名称2,选择器名称3,…{属性:属性值;属性;属性值} 例: & ...

  5. 【Django 2.2文档系列】Model 外键中的on_delete参数用法

    场景 我们用Django的Model时,有时候需要关联外键.关联外键时,参数:on_delete的几个配置选项到底是干嘛的呢,你知道吗? 参数介绍 models.CASCADE 级联删除.Django ...

  6. tp5--相对路径和绝对路径

    首先,我们要先明白相对路径和绝对路径的理论: 绝对路径:是从盘符开始的路径,形如C:\windows\system32\cmd.exe相对路径:是从当前路径开始的路径,假如当前路径为C:\window ...

  7. docker(2)

    docker三大核心组件的概念 1镜像: Docker 镜像类似于虚拟机镜像,可以将它理解为一个只读的模板.例如,一个镜像可以包含一个基本的操作系统环境,里面仅安装了 Apache 应用程序(或用户需 ...

  8. Gym 101194D Ice Cream Tower

    被一道数位DP折磨得欲仙欲死之后,再做这道题真是如同吃了ice cream一样舒畅啊 #include<bits/stdc++.h> using namespace std; #defin ...

  9. 标准库shelve

    shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  10. RHEL6 搭建 keepalived + lvs/DR 集群

    搭建 keepalived + lvs/DR  集群 使用Keepalived为LVS调度器提供高可用功能,防止调度器单点故障,为用户提供Web服务: LVS1调度器真实IP地址为192.168.4. ...