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. NIO基础之Buffer

    java.io 核心概念是流,即面向流的编程,在java中一个流只能是输入流或者输出流,不能同时具有两个概念. java.nio核心是 selector.Channel.Buffer ,是面向缓冲区( ...

  2. vue2.0:(十)、外卖App商品组件部分和better-scroll

    本篇中继续来给大家介绍外卖App制作中的商品组件的部分. 好,第一步,我们把商品的大致框架在goods.vue中搭建出来: menu-wrapper是左边菜单栏,foods-wrapper是右边商品栏 ...

  3. http://www.ibm.com/developerworks/cn/web/wa-lo-firefox-ext/index.html

    <html>    <head>        <style>                textarea{                width:800p ...

  4. jQuery toggle 使用

    jQuery 中 toggle 作用 切换元素的显示与隐藏状态 如果被选元素可见,则隐藏这些元素,如果被选元素隐藏,则显示这些元素. <body> <div class=" ...

  5. Ubuntu 配置IP地址方法

    接到一客户的服务器,开机已启动发现是Ubuntu系统,当时有点郁闷了,心想没有配置过ubuntu系统,这客户还在旁边了,心里有点紧张了,于是开始上网寻找各种方法配置,最终将IP配置好,给客户上架调试通 ...

  6. Leet-code144. Binary Tree Preorder Traversal

    这是一道将二叉树先序遍历,题目不难. 首先采用深搜递归 /** * Definition for a binary tree node. * public class TreeNode { * int ...

  7. SQL Server 2012安装配置(Part4 )

    SQL Server 2012安装配置(Part1) SQL Server 2012安装配置(Part2) SQL Server 2012安装配置(Part3 ) SQL Server 2012安装配 ...

  8. python3发送邮件01(简单例子,不带附件)

    # -*- coding:utf-8 -*-import smtplibfrom email.header import Headerfrom email.mime.text import MIMET ...

  9. COGS 1215. [Tyvj Aug11] 冗余电网

    ★   输入文件:ugrid.in   输出文件:ugrid.out   简单对比时间限制:1 s   内存限制:128 MB TYVJ八月月赛提高组第2题 测试点数目:5 测试点分值:20 --内存 ...

  10. connect() to 192.168.30.71:8082 failed (99: Cannot assign requested address) while connecting to upstream, client: 114.80.182.136, server: localhost, request: "GET /home/senior HTTP/1.1", upstream: "

    connect() to 192.168.30.71:8082 failed (99: Cannot assign requested address) while connecting to ups ...