我的LCC,LCT,Splay格式终于统一起来了。。。

另外。。这个形式的Splay是标准的Splay(怎么鉴别呢?看Splay函数是否只传了一个变量node就行),刘汝佳小白书的Splay写的真是不想吐槽了,局限性太大,别学。。。

好了我要去写维修数列了。。。。。

标准Splay模板:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
#define CH for(int d=0;d<=1;d++) if(ch[d])
using namespace std;
const int maxn=+;
struct node{
node*ch[],*fa;
int x,siz;bool rev;char c;
node(){x=;siz=;rev=false;}
void revt(){swap(ch[],ch[]);rev^=;return;}
inline void down(){
if(rev){CH{ch[d]->revt();}rev=false;}return;
}
inline void update(){
siz=;CH{siz+=ch[d]->siz;}return;
}
}Splay[maxn],*root=&Splay[];int cnt=;void print(node*x);
inline int parent(node*x,node*&y){return (y=x->fa)?y->ch[]==x?:y->ch[]==x?:-:-;}
inline void rotate(node*x){
node*y,*z;int d1=parent(x,y),d2=parent(y,z);
if(y->ch[d1]=x->ch[d1^]) y->ch[d1]->fa=y;
y->fa=x;x->fa=z;x->ch[d1^]=y;
if(d2!=-) z->ch[d2]=x;
y->update();return;
}
void pushdown(node*x){
static node*s[maxn];int top=;
for(node*y;;x=y){
s[top++]=x;y=x->fa;
if(!y||(y->ch[]!=x&&y->ch[]!=x)) break;
} while(top--) s[top]->down();return;
}
node*splay(node*x){
pushdown(x);node*y,*z;int d1,d2;
while(true){
if((d1=parent(x,y))<) break;
if((d2=parent(y,z))<){rotate(x);break;}
if(d1==d2) rotate(y),rotate(x);
else rotate(x),rotate(x);
} x->update();return x;
}
node*find(node*x,int rank){
x->down();int kth=; if(x->ch[]) kth=x->ch[]->siz+;
if(kth==rank) return x;
if(kth>rank) return find(x->ch[],rank);
else return find(x->ch[],rank-kth);
}
void split(node*&x,node*&y,int a){//
if(!a){y=x;x=NULL;return;}
x=splay(find(x,a));
y=x->ch[];x->ch[]=NULL;x->update();return;
}
void split(node*&x,node*&y,node*&z,int a,int b){//
split(x,z,b);split(x,y,a-);
return;
}
void join(node*&x,node*y){
if(!x){x=y;return;}
if(!y) return;
x=splay(find(x,x->siz));
x->ch[]=y;y->fa=x;x->update();return;
}
void join(node*&x,node*y,node*z){
join(y,z);join(x,y);return;
}
void reverse(int a,int b){
node*x,*y;split(root,x,y,a,b);x->revt();join(root,x,y);return;
}
char s[maxn];
void build(node*&x,int L,int R){
if(L>R) return;x=&Splay[++cnt];
int M=L+R>>;x->c=s[M];
build(x->ch[],L,M-);build(x->ch[],M+,R);
if(x->ch[]) x->ch[]->fa=x;
if(x->ch[]) x->ch[]->fa=x;
x->update();return;
}
inline int read(){
int x=,sig=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')sig=-;ch=getchar();}
while(isdigit(ch))x=*x+ch-'',ch=getchar();
return x*sig;
}
void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
void printer(node*x){
if(!x) return;
x->down();
printer(x->ch[]);
putchar(x->c);
printer(x->ch[]);
return;
}
void init(){
scanf("%s",s);
build(root,,strlen(s)-);
int Q=read(),L,R;
while(Q--){L=read();R=read();reverse(L,R);}
printer(root);
return;
}
void work(){
return;
}
void print(){
return;
}
int main(){init();work();print();return ;}

刘汝佳的Splay跑得虽然快但局限性太大:

 #include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
inline void read(int& x)
{
x=; char ch=getchar();int sig=;
while(!isdigit(ch)) {if(ch=='-') sig=-;ch=getchar();}
while(isdigit(ch)) x=x*+ch-'',ch=getchar();
x*=sig;
}
const int maxn=;
struct Node
{
Node* ch[];
int s,flip;
char c;
int cmp(int k)
{
if(k==ch[]->s+) return -;
return k<=ch[]->s?:;
}
void maintain(){s=ch[]->s+ch[]->s+;}
void pushdown()
{
if(flip)
{
ch[]->flip^=;ch[]->flip^=;
swap(ch[],ch[]);
flip=;
}
}
}*null=new Node(),nodes[maxn];
int tot;
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-p->ch[]->s-:k;
if(d2!=-)
{
splay(p->ch[d2],k2);
if(d==d2) rotate(o,d^);
else rotate(o->ch[d],d);
}
rotate(o,d^);
}
}
void print(Node* &o)
{
if(o==null) return;
o->pushdown();
print(o->ch[]);
printf("%c",o->c);
print(o->ch[]);
}
char s[maxn];
void build(Node* &o,int L,int R)
{
o=null;
if(L>R) return;
int M=L+R>>;
o=&nodes[tot++];
o->c=s[M];o->flip=;
build(o->ch[],L,M-);build(o->ch[],M+,R);
o->maintain();
}
Node *root,*o,*left,*mid,*right;
void merge(Node* &left,Node* &right)
{
if(left==null) left=right;
else
{
splay(left,left->s);
left->ch[]=right;
left->maintain();
}
}
void split(Node* &o,Node* &left,Node* &right,int k)
{
if(!k) left=null,right=o;
else
{
splay(o,k);
left=o;
right=left->ch[];
left->ch[]=null;
left->maintain();
}
}
int main()
{
scanf("%s",s);
build(root,,strlen(s)-);
int Q,L,R;
read(Q);
while(Q--)
{
read(L),read(R);
split(root,left,o,L-);
split(o,mid,right,R-L+);
mid->flip^=;
merge(left,mid);
merge(left,right);
root=left;
}
print(root);
return ;
}

搜索

复制

COJ 1002 WZJ的数据结构(二)(splay模板)的更多相关文章

  1. COJ 0979 WZJ的数据结构(负二十一)

    WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...

  2. COJ 0981 WZJ的数据结构(负十九)树综合

    WZJ的数据结构(负十九) 难度级别:E: 运行时间限制:3500ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 WZJ的数据结构中有很多都是关于树的.这让很多练习 ...

  3. COJ 1008 WZJ的数据结构(八) 树上操作

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=986 WZJ的数据结构(八) 难度级别:E: 运行时间限制:3000ms: ...

  4. COJ 1007 WZJ的数据结构(七) 树上操作

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=983 WZJ的数据结构(七) 难度级别:C: 运行时间限制:1000ms: ...

  5. COJ 0999 WZJ的数据结构(负一)

    WZJ的数据结构(负一) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 输入N个模板串Pi和文本串T,输出每个模板串Pi在T ...

  6. COJ 0967 WZJ的数据结构(负三十三)

    WZJ的数据结构(负三十三) 难度级别:E: 运行时间限制:7000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大 ...

  7. COJ 0970 WZJ的数据结构(负三十)树分治

    WZJ的数据结构(负三十) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给你一棵N个点的无根树,点和边上均有权值.请你设计 ...

  8. COJ 0990 WZJ的数据结构(负十)

    WZJ的数据结构(负十) 难度级别:D: 运行时间限制:5000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给你一个N个节点的有根树,从1到N编号,根节点为1并给 ...

  9. COJ 1003 WZJ的数据结构(三)ST表

    WZJ的数据结构(三) 难度级别:B: 运行时间限制:3000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大小为N的 ...

随机推荐

  1. 基于SQL的日志分析工具myselect

    基本介绍 程序开发者常常要分析程序日志,包括自己打印的日志及使用的其他软件打印的日志,如php,nginx日志等,linux环境下分析日志有一些内置命令能够使用,如grep,sort,uniq,awk ...

  2. [置顶] poj1416数字切割解题报告

    题意:有一段纸片,就是一个不超过7位数的整数,现在给定你一个目标值 aim ,让你去选择把纸片切成几段,然后这个几段的和值 最接近 aim 且不超过 aim, 分析: 对于这个纸段,比如一个 四位数的 ...

  3. Android 系统移植与驱动开发--第二章搭建Android环境核心步骤及心得

    第二章 搭建Android 开发环境 虽然在这一章中讲的是Android底层开发环境,但是相应伴随的还有Android NDK程序来测试Linux驱动,HAL程序库.底层开发不仅需要交叉编译环境,还要 ...

  4. Ajax+Node分页

    思路: ajax分页:1.服务器server.js,写布局;2.写接口文档(不管客户端,只写服务器端接口)3.写客户端,绑定数据,分页,优化点击过了,就不再请求:4.给每个li绑定点击事件,跳转详情页 ...

  5. Java遍历Map、List、Array

    1.遍历array,使用for循环或者foreach(本人建议使用) int arr[] = {2, 3, 1}; System.out.println("----1----排序前的一维数组 ...

  6. c# 用正则表达式获取开始和结束字符串中间的值

    c# 用正则表达式获取开始和结束字符串中间的值 /// <summary> /// 获得字符串中开始和结束字符串中间得值 /// </summary> /// <para ...

  7. MySQL无法登录服务器解决方法

    提示:#2000 无法登录 MySQL 服务器 今天用本机装了个phpMyAdmin,版本3.4.8,想用它来连一台内网服务器上的Mysql,于是乎修改phpMyAdmin配置文件config.inc ...

  8. SQL In的替换

    前2天在搞SQL的的时候,发现其中有很多in的操作,诸如:id in(1,2,3)或id in(select id from table……),这个对SQL来说并不是最好的选择,执行效率是偏低的[它执 ...

  9. jrae源码解析(二)

    本文细述上文引出的RAECost和SoftmaxCost两个类. SoftmaxCost 我们已经知道,SoftmaxCost类在给定features和label的情况下(超参数给定),衡量给定权重( ...

  10. 全志A10_linux3.0内核编译记录

    第一次尝试编译时按照 Android A10(4.0.3)系统编译详解.pdf 编译打包出来的镜像可用,但是内核没有生成Module.symvers .后来进一步研究才知道 ./build.sh 脚本 ...