[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/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
随机推荐
- Matlab学习-(4)
1. 函数 1.1 原始方法 之前我调用函数的方法是,首先写好函数文件,然后保存,然后在主函数中调用.这种方法的不足在于会导致你的工作目录的文件太多,从而导致很乱.在网上找了一些解决方法. 1.2 本 ...
- element-ui修改自定义主题
官方文档:https://element.eleme.cn/#/zh-CN/component/custom-theme 简单更换主题色 打开:在线主题编辑器,仅修改主题色,点击右上角[切换主题色], ...
- 推荐一个小而美的Python代码格式化工具
代码可读性是评判代码质量的标准之一,有一个衡量代码质量的标准是 Martin 提出的 “WFT” 定律,即每分钟爆出 “WTF” 的次数.你在读别人代码或者做 Code Review 的时候有没有 “ ...
- Java IO 流 -- 随机读取和写入流 RandomAccessFile (文件分割和合并)
RandomAccessFile 相对其它流多了一个seek() 方法指定指针的偏移量. 1.指定起始位置读取剩余内容 public static void test01() throws IOExc ...
- 【FishFX】花式撩骚,打造TypeScript易用框架。
· 栗子入手 假设有以下foo数组,数组中每个对象都拥有id,name两个属性,现在需要查找id > 0的对象数量. const foo: Array<{ id: number, name ...
- B站百大UP主党妹被黑客勒索!!!
4月27日,哔哩哔哩视频网站的UP主“机智的党妹”发布消息称,自己被黑客勒索了.她的视频表示:“事发突然,我被勒索了,你也有可能继续被诈骗!这种诈骗的页面是由病毒程序自动生成并留在那里的.”根据她的介 ...
- <vector>常用操作
如果不清楚vector是什么的话就去看我的另一篇随笔吧:https://www.cnblogs.com/buanxu/p/12791785.html 进入正题,vector和string一样,也是一种 ...
- 头文件<cmath>中常用函数
<cmath>里面有很多数学函数,下面说一下常用的一些函数吧:直接把函数原型给了出来,用的时候注意参数 先说一下,c++自身是没有四舍五入函数round()的,若果你要用到的话,可以自己写 ...
- JavaScript--'data-'的用法(1)
HTML5为我们提供了一个强大的功能,前段也也能实现后台数据库的效果,例如data-xxx <a href="#myModal" data-industry_id=" ...
- HTML H5响应式,表格,表单等
HTML杂项 响应式图片 <img srcset="elva-fairy-320w.jpg 320w, elva-fairy-480w.jpg 480w, elva-fairy-800 ...