以前写过这道题了,但我把以前的内容删掉了,因为现在感觉没法看

重写!


题意:

维护一个数列,支持插入一段数,删除一段数,修改一段数,翻转一段数,查询区间和,区间最大子序列


splay序列操作裸题

需要回收节点编号,所以用到$sz和nw()$,通常维护序列是不用sz的

splay维护的是这个序列,不再存在平衡树左小右大的性质

操作一段区间$[l,r]$,将$l-1\ splay$到根,$r+1\ splay$到右孩子,他的左孩子就是要操作的区间

为了方便加入两个哨兵节点

注意splay和线段树不同,每个节点都代表了一个元素

对于本题来说,因为有可能是修改成0或负数,所以tag=1表示执行了修改操作而不是修改成什么

下传标记修改会覆盖查询,无论时间先后

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define lc t[x].ch[0]
#define rc t[x].ch[1]
#define pa t[x].fa
typedef long long ll;
const int N=5e5, INF=1e9;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} int n, Q, a[N], k, tot;
char s[]; struct meow{
int ch[], fa, size, v, sum, mx, lm, rm, tag, rev;
meow() {}
meow(int val) {ch[]=ch[]=fa=tag=rev=; size=; v=sum=mx=lm=rm=val;}
}t[N];
int root, sz;
inline int wh(int x) {return t[pa].ch[] == x;}
int st[N], top;
inline int nw() {return top ? st[top--] : ++sz;} inline void paint(int x,int v) {
t[x].tag = ; t[x].v = v;
t[x].sum = t[x].size*v;
t[x].mx = t[x].lm = t[x].rm = max(t[x].sum, v);
t[x].rev = ;
}
inline void rever(int x) {
if(t[x].tag) return; //hi
t[x].rev^=;
swap(lc, rc); swap(t[x].lm, t[x].rm);
}
inline void pushDown(int x) {
if(t[x].rev) {
if(lc) rever(lc);
if(rc) rever(rc);
t[x].rev=;
}
if(t[x].tag) {
if(lc) paint(lc, t[x].v);
if(rc) paint(rc, t[x].v);
t[x].tag=;
}
} inline void update(int x) {
t[x].size = t[lc].size + t[rc].size + ;
t[x].sum = t[lc].sum + t[rc].sum + t[x].v;
t[x].mx = max(max(t[lc].mx, t[rc].mx), max(, t[lc].rm) + t[x].v + max(, t[rc].lm) );
t[x].lm = max(t[lc].lm, t[lc].sum + t[x].v + max(, t[rc].lm) );
t[x].rm = max(t[rc].rm, t[rc].sum + t[x].v + max(, t[lc].rm) );
} inline void rotate(int x) {
int f=t[x].fa, g=t[f].fa, c=wh(x);
if(g) t[g].ch[wh(f)]=x; t[x].fa=g;
t[f].ch[c] = t[x].ch[c^]; t[t[f].ch[c]].fa=f;
t[x].ch[c^]=f; t[f].fa=x;
update(f); update(x);
}
inline void splay(int x,int tar) {
for(; pa!=tar; rotate(x))
if(t[pa].fa != tar) rotate(wh(x)==wh(pa) ? pa : x);
if(tar==) root=x;
} void build(int &x,int l,int r,int f) {
int mid = (l+r)>>;
x=nw(); t[x]=meow(a[mid]); t[x].fa=f;
if(l==r) return;
if(l<mid) build(lc, l, mid-, x);
if(mid<r) build(rc, mid+, r, x);
update(x);
} inline int kth(int k) {
int x=root, lsize=;
while(x) {
pushDown(x);
int _ = lsize + t[lc].size;
if(k<=_) x=lc;
else if(k<=_+) return x;
else lsize=_+, x=rc;
}
return -;
} void Ins(int k, int tot) {
for(int i=; i<=tot; i++) a[i]=read();
int f=kth(k+); splay(f, );
int x=kth(k+); splay(x, f);
build(lc, , tot, x);
update(x); update(f);
} void erase(int x) {
if(!x) return;
st[++top]=x;
erase(lc); erase(rc);
}
void Del(int k, int tot) {
int f=kth(k); splay(f, );
int x=kth(k+tot+); splay(x, f);
erase(lc); lc=;
update(x); update(f);
} void Mak(int k, int tot) {
int f=kth(k); splay(f, );
int x=kth(k+tot+); splay(x, f);
paint(lc, read());
update(x); update(f);
} void Rev(int k, int tot) {
int f=kth(k); splay(f, );
int x=kth(k+tot+); splay(x, f);
rever(lc);
update(x); update(f);
} int Sum(int k, int tot) {
int f=kth(k); splay(f, );
int x=kth(k+tot+); splay(x, f);
return t[lc].sum;
} int main() {
//freopen("in","r",stdin);
n=read(); Q=read();
for(int i=; i<=n+; i++) a[i]=read(); a[] = a[n+] = -INF;
t[]=meow(-INF); t[].sum=t[].size=;
build(root, , n+, );
for(int i=; i<=Q; i++) { //printf("Q %d\n",i);
scanf("%s",s+);
if(s[]=='X') printf("%d\n", t[root].mx);
else {
k=read(); tot=read();
if(s[]=='I') Ins(k, tot);
if(s[]=='D') Del(k, tot);
if(s[]=='M') Mak(k, tot);
if(s[]=='R') Rev(k, tot);
if(s[]=='G') printf("%d\n", Sum(k, tot));
}
}
}

BZOJ1500: [NOI2005]维修数列 [splay序列操作]【学习笔记】的更多相关文章

  1. [bzoj1500][NOI2005 维修数列] (splay区间操作)

    Description Input 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目. 第2行包含N个数字,描述初始时的数列. 以下M行,每 ...

  2. BZOJ1500: [NOI2005]维修数列[splay ***]

    1500: [NOI2005]维修数列 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 12278  Solved: 3880[Submit][Statu ...

  3. bzoj1500: [NOI2005]维修数列 (Splay+变态题)

    Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 11353  Solved: 3553 [Submit][Status][Discuss] Descrip ...

  4. [bzoj1500][NOI2005]维修数列——splay

    题目 题解 这道题可以说是数列问题的大BOSS,也算是这一周来学习splay等数据结构的一个总结. 我们一个一个地看这些操作. 对于操作1,我们首先建一棵子树,直接接上原树即可. 对于操作2,我们找到 ...

  5. BZOJ1500 [NOI2005]维修数列(Splay tree)

    [Submit][Status][Discuss] Description 请写一个程序,要求维护一个数列,支持以下 6 种操作: 请注意,格式栏 中的下划线‘ _ ’表示实际输入文件中的空格 Inp ...

  6. [BZOJ1500][NOI2005]维修数列 解题报告 Splay

    Portal Gun:[BZOJ1500][NOI2005]维修数列 有一段时间没写博客了,最近在刚数据结构......各种板子背得简直要起飞,题目也是一大堆做不完,这里就挑一道平衡树的题来写写好了 ...

  7. [BZOJ1500][NOI2005]维修数列---解题报告

    Portal Gun:[BZOJ1500][NOI2005]维修数列 有一段时间没写博客了,最近在刚数据结构......各种板子背得简直要起飞,题目也是一大堆做不完,这里就挑一道平衡树的题来写写好了 ...

  8. 【BZOJ1500】[NOI2005]维修数列 Splay

    [BZOJ1500][NOI2005]维修数列 Description Input 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目.第2行 ...

  9. 【BZOJ-1500】维修数列 Splay

    1500: [NOI2005]维修数列 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 11047  Solved: 3460[Submit][Statu ...

随机推荐

  1. Vue-CLI 3.x 设置反向代理

    最近在项目中使用了Vue CLI 3.0版本,项目中需要设置反向代理解决跨域问题,下面记录一下设置过程. 新建配置文件 (vue-cli3.x 官网的配置文档 https://cli.vuejs.or ...

  2. 论文阅读笔记十六:DeconvNet:Learning Deconvolution Network for Semantic Segmentation(ICCV2015)

    论文源址:https://arxiv.org/abs/1505.04366 tensorflow代码:https://github.com/fabianbormann/Tensorflow-Decon ...

  3. xxl系列部署启动通用办法

    http://10.10.6.186:8080/xxl-job-admin # 编译mvn compile # 清理mvn clean # 打包mvn package # 先清理后编译mvn clea ...

  4. Echarts-各个配置项详细说明总结【转】

    1.图表标题 1 title: { 2 x: 'left', // 水平安放位置,默认为左对齐,可选为: 3 // 'center' ¦ 'left' ¦ 'right' 4 // ¦ {number ...

  5. [转] HTML5 Blob与ArrayBuffer、TypeArray和字符串String之间转换

    1.将String字符串转换成Blob对象 //将字符串 转换成 Blob 对象 var blob = new Blob(["Hello World!"], { type: 'te ...

  6. Spring boot自定义启动字符画(banner)

    spring boot项目启动时会打印spring boot的ANSI字符画,可以进行自定义. 如何自定义 实现方式非常简单,我们只需要在Spring Boot工程的/src/main/resourc ...

  7. H.265:网络视频的高清时代

    去年八月,爱立信公司推出了首款H.265编解码器,而在仅仅六个月之后,国际电联(ITU)就正式批准通过了HEVC/H.265标准,标准全称为高效视频编码(High Efficiency Video C ...

  8. Flink--Split和select

    Split就是将一个DataStream分成两个或者多个DataStream Select就是获取分流后对应的数据 val env = StreamExecutionEnvironment.getEx ...

  9. Python学习(三十一)—— Django之路由系统

    转载自:http://www.cnblogs.com/liwenzhou/p/8271147.html Django的路由系统 Django 1.11版本 URLConf官方文档 URL配置(URLc ...

  10. 如何删除github里面的项目

    第一步 :首先登陆github 第二步:如下图选择 第三步:选择如下图 第四步:点击你要删除的项目,点击settings 第五步:把页面向下拉,找到如图按钮并点击 第六步:需要确认输入你要删除的项目名 ...