treap大法好!!!

splay什么的都是异端

——XZZ

先%FHQ为敬

(fhq)treap也是可以搞区间翻转的

每次把它成(1L-1)(LR)(R+1~n)三块然后打标记拼回去

对于有标记的先交换一下左右儿子再异或一下各儿子的标记

虽说跑的不算快但还是可以挑战一下splay的

代码蒯上

//get out splay!
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
inline int gotcha()
{
register int _a=0;bool _b=1;register char _c=getchar();
while((_c<'0' || _c>'9') && _c!='-')_c=getchar();
if(_c=='-')_b=0,_c=getchar();
while(_c>='0' && _c<='9')_a=_a*10+_c-48,_c=getchar();
return _b?_a:-_a;
}
const int _ = 100007;int seed=19260817;
inline int ou(){return seed=seed*17283%2147483647;}//看RP的时候到了
int ch[_][2],d[_],rn[_],sz[_],all=0,n,root=0;
int rev[_];
inline void up(int x){sz[x]=1+sz[ch[x][0]]+sz[ch[x][1]];}//更新节点值
inline void down(int x)//向下传递翻转标记
{
if(x && rev[x])
{
rev[x]=0,swap(ch[x][0],ch[x][1]);
if(ch[x][0])rev[ch[x][0]]^=1;
if(ch[x][1])rev[ch[x][1]]^=1;
}
}
inline int malloc(int v){sz[++all]=1;d[all]=v;rn[all]=ou();return all;}//新建一个节点
inline int merge(int a,int b)
{
if(!a || !b) return a+b;down(a),down(b);
if(rn[a]<rn[b]){ch[a][1]=merge(ch[a][1],b);up(a);return a;}
else{ch[b][0]=merge(a,ch[b][0]);up(b);return b;}
}
void split(int now,int k,int &a,int &b)
{
if(!now){a=b=0;return;}
down(now);
if(k<=sz[ch[now][0]])b=now,split(ch[now][0],k,a,ch[now][0]);
else a=now,split(ch[now][1],k-sz[ch[now][0]]-1,ch[now][1],b);
up(now);
}
int plant(int l,int r)//种树
{
if(l>r)return 0;
int mid=(l+r)>>1,now=malloc(mid-1);
ch[now][0]=plant(l,mid-1);ch[now][1]=plant(mid+1,r);
up(now);return now;
}
void print(int now)//按中序遍历输出答案
{
if(!now)return;down(now);
print(ch[now][0]);
if(d[now]>=1 && d[now]<=n)printf("%d ",d[now]);
print(ch[now][1]);
return;
}
void reverse(int l,int r)//旋转
{
int a,b,c;
split(root,l-1,a,b),split(b,r-l+1,b,c);
rev[b]^=1;
root=merge(a,merge(b,c));
}
int main()
{
register int m,l,r;
n=gotcha();m=gotcha();
root=plant(2,n+3);
while(m--)
{
l=gotcha(),r=gotcha();
reverse(l,r);
}
print(root);
return 0;
}

treap坠强!

如何用treap写luogu P3391的更多相关文章

  1. [luogu P3391] 文艺平衡树

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

  2. 如何用ActiveQt写导出类

    如何用ActiveQt写导出类 最近一直在用ActiveQt框架来写ActiveX插件, 由于项目需要提示类的导出, 所以上午捣鼓了一下, 现在记录记录.其实内容主要是把Qt手册里自己用到的部分整理一 ...

  3. linux常用终端指令+如何用vim写一个c程序并运行

    在装好ubuntu之后今天学习了一些linux的一些基础知识: windows里面打开命令窗口是win+r,在linux系统里面,ctrl+alt+t打开终端,今天的一些指令都是围绕终端来说的 首先s ...

  4. 2019-2-13-Latex-论文elsevier,手把手如何用Latex写论文

    title author date CreateTime categories Latex 论文elsevier,手把手如何用Latex写论文 lindexi 2019-02-13 10:38:20 ...

  5. Luogu P3391 文艺平衡树(Splay or FHQ Treap)

    这道题要求区间反转...好东西.. 对于Splay:把l-1旋到根,把r+1旋到根的右儿子,这样r+1的左儿子就是整个区间了,然后对这个区间打个tg 注意要插-Inf和Inf到树里面,防止越界,坐标要 ...

  6. luogu P3391 【模板】文艺平衡树(Splay) 非旋转treap

    Code: #include<bits/stdc++.h> using namespace std; void setIO(string s) { string in=s+".i ...

  7. Luogu P3391 【模板】文艺平衡树 Splay 平衡树

    https://www.luogu.org/problemnew/show/P3391 以前写过题解的入门题重写练板子.wdnmd真就 ' == ' 写成 ' = ' 了编译器不报错呗. #inclu ...

  8. Luogu P3391 【模板】文艺平衡树(FHQ-Treap)

    题意 给出一个长为$n$序列$[1,2,...,n]$,$m$次操作,每次指定一段区间$[l,r]$,将这段区间翻转,求最终序列 题解 虽然标题是$Splay$,但是我要用$FHQ\ Treap$,考 ...

  9. 如何用java写出无副作用的代码

    搞java的同学们可能对无副作用这个概念比较陌生,这是函数式编程中的一个概念,无副作用的意思就是: 一个函数(java里是方法)的多次调用中,只要输入参数的值相同,输出结果的值也必然相同,并且在这个函 ...

随机推荐

  1. 【转】pom.xml讲解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  2. 编译错误you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)

    解决方法: export FORCE_UNSAFE_CONFIGURE=1

  3. MySQL++简单使用记录.md

    #1.简介 MySQL++ is a powerful C++ wrapper for MySQL’s C API. Its purpose is to make working with queri ...

  4. JavaScript_6_函数

    函数是由事件驱动的或者当它被调用执行的可重复使用的代码块 调用带参数的函数 带有返回值的函数 <!DOCTYPE html> <html> <head> <t ...

  5. HDU 2149 Public Sale 拍卖(巴什博弈)

    思路:只要能给对方留下n+1,我就能胜,否则败. #include <iostream> #include <cstdio> using namespace std; int ...

  6. 如何处理VirtualBox启动错误消息:The vboxdrv kernel module is not loaded

    我在启动minikube时,遇到如下错误消息: Starting local Kubernetes v1.10.0 cluster... Starting VM... E1010 03:27:37.9 ...

  7. uva806 Spatial Structures 空间结构 (黑白图像的四分树表示)

    input 8 00000000 00000000 00001111 00001111 00011111 00111111 00111100 00111000 -8 9 14 17 22 23 44 ...

  8. 多线程程序设计-Thread的一些方法

    run():是程序中会和会和其他线程“同时”执行的部分.   wait():使得当前线程进入等待状态,等待的线程不会主动进入到线程队列中排队等待cpu资源,必须由其他线程调用notify()方法通知它 ...

  9. 01_9_Struts用ModelDriven接收参数

    01_9_Struts用ModelDriven接收参数 1. 配置struts.xml文件 <package name="user" namespace="/use ...

  10. 课下作业04-2String的使用方法

    1.动手动脑之String.equals()方法public class StringEquals { public static void main(String[] args) { String ...