splay区间翻转即可

/**************************************************************
Problem: 3223
User: walfy
Language: C++
Result: Accepted
Time:2304 ms
Memory:5444 kb
****************************************************************/ //#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; struct Splay{
struct Node{
Node* ch[];
int v;
int s;
int flip;
int cmp(int x)const{
int d = x - ch[]->s;
if(d==)return -;
return d<= ? :;
}
void maintain()
{
s = + ch[]->s + ch[]->s;
}
void pushdown()
{
if(flip)//类似于线段树的lazy标记
{
flip=;
swap(ch[],ch[]);
ch[]->flip = !(ch[]->flip);
ch[]->flip = !(ch[]->flip);
}
}
};
Node* null;
void Rotate(Node* &o,int d)
{
Node* k = o->ch[d^];
o->ch[d^] = k->ch[d];
k->ch[d] = o;
o->maintain();k->maintain();
o = k;
}
void splay(Node* &o,int k)
{
o->pushdown();
int d = o->cmp(k);
if(d==)k -= o->ch[]->s + ;//利用二叉树性质
if(d!=-)
{
Node* p = o->ch[d];
p->pushdown();
int d2 = p->cmp(k);
int k2 = (d2== ? k:k-p->ch[]->s-);
if(d2!=-)
{
splay(p->ch[d2],k2);
if(d==d2)Rotate(o,d^);
else Rotate(o->ch[d],d);
}
Rotate(o,d^);
}
}
Node* Merge(Node* left,Node* right)
{
splay(left,left->s);//把排名最大的数splay到根
left->ch[] = right;
left->maintain();
return left;
}
void split(Node* o,int k,Node* &left,Node* &right)
{
splay(o,k);//把排名为k的节点splay到根,右侧子树所有节点排名比k大,左侧小
right = o->ch[];
o->ch[] = null;
left = o;
left->maintain();
}
Node *root,*left,*right;
void init(int sz)
{
null=new Node;
null->s=;
root=new Node;
root->v=;root->flip=;
root->ch[]=root->ch[]=null;
root->maintain();
Node* p;
for(int i=;i<=sz;i++)
{
p=new Node;
p->v=i;p->s=p->flip=;
p->ch[]=root,p->ch[]=null;
root=p;
root->maintain();
}
}
void gao(int n,int l,int r)
{
if(l==&&r==n)root->flip^=;
else if(l==)
{
split(root,r,left,right);
left->flip^=;
root=Merge(left,right);
}
else if(r==n)
{
split(root,l-,left,right);
right->flip^=;
root=Merge(left,right);
}
else
{
Node *mid;
split(root,r,left,right);
split(left,l-,left,mid);
mid->flip^=;
root=Merge(Merge(left,mid),right);
}
}
void print(Node *o)
{
o->pushdown();
if(o->ch[]!=null)print(o->ch[]);
printf("%d ",o->v);
if(o->ch[]!=null)print(o->ch[]);
}
}sp;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
sp.init(n);
for(int i=;i<m;i++)
{
int l,r;
scanf("%d%d",&l,&r);
sp.gao(n,l,r);
}
sp.print(sp.root);
return ;
}
/******************** ********************/

bzoj3223: Tyvj 1729 文艺平衡树 splay裸题的更多相关文章

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

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

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

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

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

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6881  Solved: 4213[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)

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

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

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

  7. 【BZOJ3223】 Tyvj 1729 文艺平衡树 Splay

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

  8. 【Splay】bzoj3223 Tyvj 1729 文艺平衡树

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #i ...

  9. 【Splay】【块状链表】bzoj3223 Tyvj 1729 文艺平衡树

    让蒟蒻见识到了常数大+滥用STL的危害. <法一>很久之前的Splay #include<cstdio> #include<algorithm> using nam ...

随机推荐

  1. CH1402 后缀数组【Hash】【字符串】【二分】

    1402 后缀数组 0x10「基本数据结构」例题 描述 后缀数组 (SA) 是一种重要的数据结构,通常使用倍增或者DC3算法实现,这超出了我们的讨论范围.在本题中,我们希望使用快排.Hash与二分实现 ...

  2. html lang="zh-cn"解决Mac版Firefox中文字体显示问题

    这两天在Mac下被Firefox的中文字体显示问题所困扰.在Firefox中将Sans-serif字体设置为SimSun-ExtB(新宋体)或英文字体(这时会用Mac默认中文字体),如下图: 浏览园子 ...

  3. SpringCloud 进阶之Zuul(路由网关)

    1. Zuul(路由网关) Zuul 包含了对请求的路由和过滤两个最主要的功能; 路由功能:负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础; 过滤功能:负责对请求的处理过程进行干 ...

  4. My Emacs Writing Setup

    My Emacs Writing Setup Table of Contents 1. About this Document 1.1. Related Materials 1.2. Change H ...

  5. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  6. 001-ant design安装及快速入门【基于纯antd的基本项目搭建】

    一.安装使用 1.1.安装 推荐使用 npm 或 yarn 的方式进行开发 npm install antd --save yarn add antd 1.2.浏览器引入 在浏览器中使用 script ...

  7. lua实现单例模式

    Singleton = {} function Singleton:new(o) o = o or {} setmetatable(o,self) self.__index = self return ...

  8. Java 动态代理是基于什么原理

    动态代理 ①动态代理概念理解 动态代理是一种方便运行时动态构建代理.动态处理代理方法调用的机制,很多场景都利用类似机制做到的,比如用来包装RPC调用.面向切面的变成(AOP) 实现动态代理的方式很多, ...

  9. window.location.href = basePath + "paper/deleteExpertComment.action?expertId="+$(this).prev().val();

    window.location.href = basePath + "paper/deleteExpertComment.action?expertId="+$(this).pre ...

  10. 在apache中使用.htaccess文件的注意事项

    在apache的配置文件中: <VirtualHost *:80> ServerName tp5.com DocumentRoot d:/wamp/www/tp5.com/public & ...