[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. 【源码分享】mui实现简单的手机音乐播放器

    mui实现简单的手机音乐播放器 最近先来无事,我用mui写了一个可以跨页面控制的音乐播放器.主要功能有上一曲,下一曲,播放,暂停,感兴趣的可以继续看下去. 说的总是不实在,直接上源码,有兴趣的可以读下 ...

  2. 【LeetCode】112. Path Sum

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  3. 程序员必须知道的六大ES6新特性

    二 .字符串扩展 1.传统上,JavaScript只有indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中.ES6又提供了三种新方法. includes():返回布尔值,表示是否找到了参 ...

  4. Linux之用户管理--初级上

    管理用户命令汇总 命令 注释说明(特殊颜色的必须掌握) useradd增 同adduser命令,执行此命令可在系统中添加用户.(更改4个用户文件) userdel删 执行此命令可删除用户及相关用户的配 ...

  5. const vector<int> 和 vector<const int>问题讨论

    1.const vector <int> vec(10) —— 与const int a[10]是一回事,意思是vec只有10个元素,不能增加了,里面的元素也是不能变化的 vector&l ...

  6. Linux进程/内核模型

    内核必须实现一组服务和相应的接口,应用程序则可以使用这些接口,而不是直接与硬件打交道. Linux内核主要由以下5个子系统组成:进程调度.内存管理.虚拟文件系统.进程间通信以及设备驱动. 在这个组成中 ...

  7. java equals和==区别及string类的说明

    一.equals和==的区别 1.1.equals之string字符串的比较 1.1.1.源码如下图 if (this == anObject) {            return true;  ...

  8. 如何在一个Eclipse同时启动两个Tomcat

    比如:有两个版本的tomcat,一个5.*,一个6.*,此时由于两个工程分别部署在两个版本的tomcat下,需要同时启动两个tomcat,以下是方法: 1.特别要注意: 不要设置CATALINA_HO ...

  9. org.apache.jasper.JasperException: - Page directive must not have multiple occurrences of pageencoding

    最近写jsp遇到一系列的低级错误,记录下来权当前车之鉴吧. 错误提示: SEVERE: Servlet.service() for servlet jsp threw exceptionorg.apa ...

  10. JavaScript+svg绘制的一个动态时钟

    结果图: 代码如下: <!DOCTYPE html> <html> <head> <title>动态时钟</title> </head ...