[hdu3308]线段树
题意:单点更新,区间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]线段树的更多相关文章
- LCIS hdu3308 (线段树 区间合并)
题意: 有两种操作 一种是单点改为b 一种是给出区间ab 区间ab的最大上升子序列个数.. 线段树目前学了三种 第一种单点操作很简单 第二种区域操作加上懒惰标记即可 现在这种 为区间合并. ...
- HDU3308 线段树(区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU3308 线段树区间合并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 ,简单的线段树区间合并. 线段树的区间合并:一般是要求求最长连续区间,在PushUp()函数中实 ...
- hdu3308 线段树 区间合并
给n个数字 U表示第A个数改为B.A是从0开始. Q输出最大的递增序列个数. 考虑左边,右边,和最大的. #include<stdio.h> #define lson l,m,rt< ...
- hdu3308 线段树——区间合并
更新一个点: 求某个区间的最长连续上升序列: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 #include <cstdio> #in ...
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU3308(LCIS) 线段树好题
题目链接:传送门 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y 2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 题目思路: ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
随机推荐
- 计算机系统基础学习笔记(1)-基本GCC,objdump,GBD命令的使用
基本GCC命令的使用 GCC是一套由GNU项目开发的编程语言编译器,可处理C语言. C++.Fortran.Pascal.Objective-C.Java等等.GCC通常是 跨平台软件的编译器首选.g ...
- 运行一个nodejs服务,先发布为deployment,然后创建service,让集群外可以访问
问题来源 海口-老男人 17:42:43 就是我要运行一个nodejs服务,先发布为deployment,然后创建service,让集群外可以访问 旧报纸 17:43:35 也就是 你的需求为 一个a ...
- 测试需要用到的chrome调试
模拟慢网速 断开网络 F12后勾选上offline 请求304 后来发现是选中了该浏览其的Disable cache,去掉就好了.
- Laravel - 上手实现 - 文件上传、保存到 public 目录下
1.为了访问方便,将上传的文件保存在 public 目录下,需要进行修改配置. 找到 config/filesystems.php 文件然后修改 root.具体如下: 'local' => [ ...
- .NetCore对接各大财务软件凭证API——金蝶系列(1)
哈喽,又和大家见面了,虽然看文章的小伙伴不多,但是我相信总有一天,自己写的这些文章或多或少会对其他人有些帮助,让他们在相关的业务开发下能少走些弯路,那我的目的就达到了,好了,今天就正式开始我们的系列了 ...
- vue显示富文本
来源:https://segmentfault.com/q/1010000013952512 用 v-html 属性解决
- cocos2dx初体验
我们创建工程后总会自带一个HelloWorld类,短短的几行代码就出来了一个游戏的雏形,请问我们真的理解它了吗?如果我们能早一点弄明白这几行代码,我们或许会比现在走得更远. 理解HelloWorld类 ...
- 快速部署一个Kubernetes集群
官方提供的三种部署方式 minikube Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,仅用于尝试Kubernetes或日常开发的用户使用. 部署地址:https:// ...
- vs code 打开文件时,取消文件目录的自动定位跟踪
文件-->首选项-->设置-->在搜索栏中搜索:explorer.autoReveal; 去掉勾选即可.
- 串口字符串-HEX格式
串口字符串-HEX格式 C++SerialSerialPortHEX 介绍 串口通信过程中 通常涉及一个数据的模拟过程以及数据发送过程, 一般来说, 我们会发送一串指令给下位机 68 05 00 84 ...