[Tvyj 1729]文艺平衡树

题目

您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 4 1

INPUT

第一行为n,m n表示初始序列有n个数,这个序列依次是(1,2……n-1,n) m表示翻转操作次数
接下来m行每行两个数[l,r] 数据保证 1<=l<=r<=n

OUTPUT

输出一行n个数字,表示原始序列经过m次变换后的结果

SAMPLE

INPUT

5 3
1 3
1 3
1 4

OUTPUT

4 3 2 1 5

解题报告

板子题,Splay,fhq-Treap什么的,我半个都不会呢= =
上板子= =
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
inline int read(){
int sum();
char ch(getchar());
while(ch<''||ch>'')
ch=getchar();
while(ch>=''&&ch<=''){
sum=sum*+ch-'';
ch=getchar();
}
return sum;
}
int n,m,top;
struct node{
int v,key,size,mark;
node *ch[];
node(int x=):size(),key(rand()),mark(),v(x){
ch[]=ch[]=NULL;
}
inline void revs();
inline void pushup();
inline void pushdown(){
if(mark){
if(ch[])
ch[]->revs();
if(ch[])
ch[]->revs();
mark=;
}
}
}*root,*st[];
typedef pair<node*,node*>p;
inline void swp(node *x,node *y){
node *tmp(x);
x=y;
y=tmp;
}
inline int get_size(node *x){
if(x==NULL)
return ;
return x->size;
}
inline void node::revs(){
mark^=;
swap(ch[],ch[]);
}
inline void node::pushup(){
size=;
size+=get_size(ch[])+get_size(ch[]);
}
inline node* build(){
node *x,*las;
for(int i=;i<=n;i++){
x=new node(i);
las=NULL;
while(top&&st[top]->key>x->key){
st[top]->pushup();
las=st[top];
st[top--]=NULL;
}
if(top)
st[top]->ch[]=x;
x->ch[]=las;
st[++top]=x;
}
while(top)
st[top--]->pushup();
return st[];
}
inline node* merge(node *x,node *y){
if(x==NULL)
return y;
if(y==NULL)
return x;
if(x->key<y->key){
x->pushdown();
x->ch[]=merge(x->ch[],y);
x->pushup();
return x;
}
else{
y->pushdown();
y->ch[]=merge(x,y->ch[]);
y->pushup();
return y;
}
}
inline p split(node *x,int k){
if(!x)
return p(NULL,NULL);
p y;
x->pushdown();
if(get_size(x->ch[])>=k){
y=split(x->ch[],k);
x->ch[]=y.second;
x->pushup();
y.second=x;
}
else{
y=split(x->ch[],k-get_size(x->ch[])-);
x->ch[]=y.first;
x->pushup();
y.first=x;
}
return y;
}
inline int rk(node *rt,int x){
if(!rt)
return ;
return x<rt->v?rk(rt->ch[],x):rk(rt->ch[],x)+get_size(rt->ch[])+;
}
inline int kth(int k){
p x(split(root,k-)),y(split(x.second,));
node *tmp(y.first);
root=merge(merge(x.first,tmp),y.second);
return tmp->v;
}
inline void insert(int x){
int k(rk(root,x));
p tp(split(root,k));
node *tmp(new node(x));
root=merge(merge(tp.first,tmp),tp.second);
}
inline void print(node *x){
if(!x)
return;
x->pushdown();
print(x->ch[]);
printf("%d ",x->v);
print(x->ch[]);
}
inline int gg(){
srand(time(NULL));
n=read(),m=read();
root=build();
for(int i=;i<=m;i++){
int x(read()),y(read());
if(x==y)
continue;
p tmp1(split(root,x-)),tmp2(split(tmp1.second,y-x+));
tmp2.first->revs();
root=merge(tmp1.first,merge(tmp2.first,tmp2.second));
}
print(root);
}
int k(gg());
int main(){;}
代码极其漂(chou)亮(lou),请慢(gan)慢(jin)欣(tui)赏(chu)

[补档][Tvyj 1729]文艺平衡树的更多相关文章

  1. [BZOJ3223]Tyvj 1729 文艺平衡树

    [BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...

  2. BZOJ3223: Tyvj 1729 文艺平衡树 [splay]

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3595  Solved: 2029[Submit][Sta ...

  3. BZOJ 3223: Tyvj 1729 文艺平衡树

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3628  Solved: 2052[Submit][Sta ...

  4. bzoj3223 Tyvj 1729 文艺平衡树(Splay Tree+区间翻转)

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2202  Solved: 1226[Submit][Sta ...

  5. BZOJ 3223: Tyvj 1729 文艺平衡树(splay)

    速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...

  6. 3223: Tyvj 1729 文艺平衡树

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1347  Solved: 724[Submit][Stat ...

  7. bzoj3223Tyvj 1729 文艺平衡树 splay

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 5644  Solved: 3362[Submit][Sta ...

  8. bzoj 3223: Tyvj 1729 文艺平衡树 (splay)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3223 题面: 3223: Tyvj 1729 文艺平衡树 Time Limit: 10 S ...

  9. BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6881  Solved: 4213[Submit][Sta ...

随机推荐

  1. SICP-Elements of program

    编程语言=组合简单形成复杂的工具 简单的声明和表达式 简单元素之间的组合方式 组合后元素的抽象方式 程序=数据+函数 数据是我们要处理的内容 函数是我们处理数据的方式 函数式与中缀式 函数式不会出现歧 ...

  2. HTML5 中的拖放

    今天,给大家整理一个html5 拖放. 首先,我们先了解一下什么是拖放? 拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HT ...

  3. python爬虫从入门到放弃前奏之学习方法

    首谈方法 最近在整理爬虫系列的博客,但是当整理几篇之后,发现一个问题,不管学习任何内容,其实方法是最重要的,按照我之前写的博客内容,其实学起来还是很点枯燥不能解决传统学习过程中的几个问题: 这个是普通 ...

  4. jrebel配置热部署参数

    jrebel配置热部署参数: -noverify -agentpath:D:/jrebel/lib/jrebel64.dll -Drebel.dirs=E:/workspace/item/src/ma ...

  5. Cordova(PhoneGap) 环境搭建与基础

    Cordova(PhoneGap) 创建步骤:官方Guide 环境准备 安装 Node.js nodejs.org 安装 git git-scm.com (bin目录添加到path) 安装 cordo ...

  6. PowerShell使用-debug定位问题

    PowerShell就像它的名字一样,很强大,用起来很方便,所以微软基本上所有的主流企业级产品都支持PowerShell,Azure也不例外.通过Azure门户网站固然是简单直观,但对于很多IT管理员 ...

  7. C# 来做 视频播放 视频流处理 转码 实时传输

    最近一直在研究视频实时查看播放 很遗憾 只成功了一半 记录一下历程 以便大家相互交流 项目需求是  GPS 视频设备  连接服务器  将视频流走RTP  协议发送到服务器 服务器将接收的视频流 传输给 ...

  8. git常用基本命令

    一定要以管理员的身份打开,否则有些命令不能用,比如ssh -T git@github.com(查看配置ssh是否成功)@初始化git git config --global user.name ruo ...

  9. spring整合axis2(最小配置化)的示例

    参考文档: http://blog.csdn.net/xinhaoluan/article/details/3605234 环境配置: spring-framework-3.2.7 axis2-1.6 ...

  10. VB6之ICMP实现ping功能

    代码备忘 'code by lichmama from cnblogs.com Private Type IPAddr ip1 As Byte ip2 As Byte ip3 As Byte ip4 ...