我的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. 3DS MAX 导出FBX到Unity3D设置

  2. [AWS S3] Hosting a Static Website on Amazon S3

    In this lesson, you will learn how to host a static website on Amazon S3. I will show you how to cre ...

  3. 在 Java 中高效使用锁的技巧--转载

    竞争锁是造成多线程应用程序性能瓶颈的主要原因 区分竞争锁和非竞争锁对性能的影响非常重要.如果一个锁自始至终只被一个线程使用,那么 JVM 有能力优化它带来的绝大部分损耗.如果一个锁被多个线程使用过,但 ...

  4. common-httpclient 用户名密码认证示例

    import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.com ...

  5. Android -- 利用Broadcast开启Service(转)

    Broadcast和Service都是Android四大组建之一的. 这里的广播是动态的,自己注册的一个广播. 这种最典型的用法就是利用开机广播,然后再起自己的服务,也就是在Android手机中做到开 ...

  6. 模板-->欧几里得算法

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 简单的测试 None 代码模板 /* * TIME complexity:O(logN) means very fast. ...

  7. codevs 1994 排队 排列组合+高精度

    /* 数学题0.0 最后答案:A(n,n)*A(n+1,2)*A(n+3,m)+A(n,n)*C(m,1)*A(2,2)*C(n+1,1)*A(n+2,m-1); 简单解释一下 +之前的很显然 先排男 ...

  8. ASP.NET-FineUI开发实践-13(一)

    开原版好像是没有gird树,有一个扩展列下的模拟树列,就是不能展开,专业版有,开原版我弄了弄,思路是有,就是不是很好实现.这篇博客直接写出了(一)说明一个肯定是写不完的. FineUI重在封装,改这个 ...

  9. 二维码生成Demo

    在C#中直接引用ThoughtWorks.QRCode.dll 类, 下载 dll 类 http://file.111cn.net/download/2013/06/29/20120516165420 ...

  10. Cloud Foundry中 JasperReports service集成

    Cloud Foundry作为业界第一个开源的PaaS解决方案,正越来越多的被业界接受和认可.随着PaaS的发展,Cloud Foundry顺应潮流,充分发挥开源项目的特点,到目前为止,已经支持了大批 ...