思路:

区间翻转的裸题 终于tm理解splay了……

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 155555
int n,m,root,size[N],ch[N][2],fa[N],rev[N],v[N];
void push_up(int x){size[x]=size[ch[x][0]]+size[ch[x][1]]+1;}
int build(int l,int r){
if(l>r)return 0;
if(l==r){size[l]=1,v[l]=l-1;return l;}
int mid=(l+r)>>1;v[mid]=mid-1;
ch[mid][0]=build(l,mid-1);fa[ch[mid][0]]=mid;
ch[mid][1]=build(mid+1,r);fa[ch[mid][1]]=mid;
push_up(mid);
return mid;
}
void rotate(int p){
int q=fa[p],y=fa[q],f=(ch[q][1]==p);
ch[q][f]=ch[p][!f],fa[ch[q][f]]=q;
ch[p][!f]=q;fa[q]=p;fa[p]=y;
if(y){
if(ch[y][0]==q)ch[y][0]=p;
else ch[y][1]=p;
}push_up(q);
}
void Splay(int x,int tp){
for(int y;y=fa[x];rotate(x)){
if(y==tp)break;
if(fa[y]!=tp){
if((ch[y][0]==x)^(ch[fa[y]][0]==y))rotate(x);
else rotate(y);
}
}push_up(x);
if(!tp)root=x;
}
void push_down(int x){
if(rev[x]){
rev[ch[x][0]]^=1,rev[ch[x][1]]^=1;
swap(ch[x][0],ch[x][1]);
rev[x]=0;
}
}
int find(int x,int num){
push_down(x);
int sz=size[ch[x][0]];
if(sz+1==num)return x;
else if(sz+1>num)return find(ch[x][0],num);
else return find(ch[x][1],num-sz-1);
}
void reverse(int l,int r){
int y=find(root,l);Splay(y,0);
Splay(find(root,r+2),y);
rev[ch[ch[root][1]][0]]^=1;
}
void dfs(int x){
push_down(x);
if(ch[x][0])dfs(ch[x][0]);
if(v[x]&&v[x]!=n+1)printf("%d ",v[x]);
if(ch[x][1])dfs(ch[x][1]);
}
int main(){
scanf("%d%d",&n,&m);
root=build(1,n+2);
for(int i=1;i<=m;i++){
int l,r;
scanf("%d%d",&l,&r);
reverse(l,r);
}
dfs(root);
}

BZOJ 3223 Splay区间翻转的更多相关文章

  1. bzoj 3223 文艺平衡树 splay 区间翻转

    Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 17715  Solved: 7769[Submit][Status][ ...

  2. bzoj 1251序列终结者 splay 区间翻转,最值,区间更新

    序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 4594  Solved: 1939[Submit][Status][Discuss] De ...

  3. bzoj 3223 splay模板题3

    水题...貌似理解splay怎么维护数列了... 每个点维护一个size,它的位置就是它的size,区间翻转的话可以打标记,find的时候push_down,交换左右子树. #include<i ...

  4. hdu-1890-Robotic Sort splay区间翻转

    题意: 依次找第i大的数下标pos[i],然后将区间[i,pos[i]]翻转 分析: splay树区间翻转 // File Name: ACM/HDU/1890.cpp // Author: Zlbi ...

  5. splay区间翻转

    原题P3391 [模板]文艺平衡树(Splay) 题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: ...

  6. Splay(区间翻转)&树套树(Splay+线段树,90分)

    study from: https://tiger0132.blog.luogu.org/slay-notes P3369 [模板]普通平衡树 #include <cstdio> #inc ...

  7. hdu1890 Robotic Sort (splay+区间翻转单点更新)

    Problem Description Somewhere deep in the Czech Technical University buildings, there are laboratori ...

  8. 2019牛客国庆集训派对day1 K题 双向链表练习题 splay区间翻转

    题目链接: 解法: 先建n颗平衡树,合并的时候将a中最右的结点翻转到根节点,b中最左的结点翻转到根节点,对合并后的根节点进行标记. #include <bits/stdc++.h> usi ...

  9. BZOJ 3223 Tyvj 1729 文艺平衡树(Splay)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3223 [题目大意] 给出一数列,问m次区间翻转后的结果. [题解] Splay 区间翻 ...

随机推荐

  1. 基于redis ae实现 Linux中的文件系统监控机制(inotify)

    (英文部分为转的.代码是个人代码) 1 What's inotify  The inotify API provides a mechanism for monitoring file system ...

  2. Android基础新手教程——1.5.2 Git之使用GitHub搭建远程仓库

    Android基础新手教程--1.5.2 Git之使用GitHub搭建远程仓库 标签(空格分隔): Android基础新手教程 本节引言: 在上一节中.我们学习了怎样使用Git.构建我们的本地仓库.轻 ...

  3. hdu4390-Number Sequence(容斥计算)

    题意:给定b数列.计算有多少种数列 a1,a2,...,an 满足条件 a1*a2*...*an=b1*b2*-*bn (ai>1). 解法:处理出b数列中出现的全部质因子的数量记录在map中, ...

  4. Mosquito的优化——epoll优化(七)

    本文由逍遥子撰写,转发请标注原址: http://blog.csdn.net/houjixin/article/details/46413583 或 http://houjixin.blog.163. ...

  5. bzoj1045: [HAOI2008] 糖果传递(数论)

    1045: [HAOI2008] 糖果传递 题目:传送门(双倍经验3293) 题解: 一开始想着DP贪心一顿乱搞,结果就GG了 十分感谢hzwer大佬写的毒瘤数论题解: 首先,最终每个小朋友的糖果数量 ...

  6. iOS-UITextField 全面解析

    iOS中UITextField 使用全面解析 建议收藏,用到的时候来这里一查就都明白了 //初始化textfield并设置位置及大小 UITextField *text = [[UITextField ...

  7. nyoj--55--懒省事的小明(STL优先队列)

    懒省事的小明 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述       小明很想吃果子,正好果园果子熟了.在果园里,小明已经将所有的果子打了下来,而且按果子的不同种类分 ...

  8. 1. Git-2.12.0-64-bit .exe下载

    转自:https://blog.csdn.net/u011164906/article/details/59129835 之前一直用SVN最近接触git,Git-2.12.0-64-bit .exe文 ...

  9. python 3.x 学习笔记12 (反射 and 异常)

    1.反射通过字符串映射或修改程序运行时的状态.属性.方法 getattr(obj,name_str):  根据字符串name_str去获取obj对象里的对应的方法的内存地址 hasttr(obj,na ...

  10. swift语言点评十三-Lazy

    Lazy Stored Properties A lazy stored property is a property whose initial value is not calculated un ...