题意:单点更新,区间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. springboot前后端分离跨域

    @Configurationpublic class CrossConfig implements WebMvcConfigurer { @Override public void addCorsMa ...

  2. 详解 Collections类

    (请关注 本人"集合总集篇"博文--<详解 集合框架>) 有的同学可能会有这样的疑问 -- Collections类也是集合吗? 答曰:非也! 那为什么要讲解这个类呢? ...

  3. [php] phpStudy+XDebug配置

    一.配置前说明: 1.phpStudy集成了XDebug扩展,所以不用单独下载XDebug. 2.打开XDebug扩展:其它选项菜单 > PHP扩展 > Xdebug 二.配置步骤: ph ...

  4. myod实验(选做)

    myod实验 实验任务 1 复习c文件处理内容 2 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能 main与其他分开,制作静态库和动态库 编写Makefile ...

  5. 2019-2020-1 20199329《Linux内核原理与分析》第十一周作业

    <Linux内核原理与分析>第十一周作业 一.本周内容概述: 学习linux安全防护方面的知识 完成实验楼上的<ShellShock 攻击实验> 二.本周学习内容: 1.学习& ...

  6. REDHAT7进入单用户模式

    Redhat7采用的是grub2,和Redhat6.x进入单用户的方法不同. 一.init方法 1.centos7的grub2界面会有两个入口,正常系统入口和救援模式: 2.修改grub2引导 在正常 ...

  7. [Inno Setup] 对比字符串

    [Code] var MD5Comp: string; procedure ExitProcess(uExitCode:UINT); external 'ExitProcess@kernel32.dl ...

  8. Shell中的here文档

    1.名词解释: 以下是维基百科解释: here文档[1],又称作heredoc.hereis.here-字串或here-脚本,是一种在命令行shell(如sh.csh.ksh.bash.PowerSh ...

  9. Spring Boot devtool的使用

    文章目录 添加Spring Boot devtool依赖 默认属性 自动重启 Live Reload 全局配置 Spring Boot devtool的使用 Spring Boot为我们提供了一个便捷 ...

  10. MongoDB学习(三)

    MongoDB条件操作符 $gt  > 大于 $lt   < 小于 $gte >= 大于等于 $lte  <= 小于等于 $ne  !=  不等于 条件操作符可用于查询语句中, ...