(╯-_-)╯╧╧

此处为错误代码。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 300050
#define inf 2147483646
using namespace std;
int n,m,a[maxn],x,y;
int tree[maxn][],size[maxn],fath[maxn],val[maxn],root,hash[maxn],rr=;
char s[];
void pushup(int now)
{
size[now]=size[tree[now][]]+size[tree[now][]]+;
}
void reset(int x)
{
fath[x]=tree[x][]=tree[x][]=;
size[x]=;
}
void sets(int x,int y)
{
swap(fath[x],fath[y]);
if (fath[x]==y)
{
fath[x]=fath[y];fath[y]=x; }
}
void build(int &now,int left,int right,int father)
{
if (left>right) return;
int mid=(left+right)>>;now=mid;
fath[now]=father;val[now]=a[mid];
build(tree[now][],left,mid-,now);
build(tree[now][],mid+,right,now);
pushup(now);
}
void rotate(int x,int &k)
{
int y=fath[x],z=fath[y],l,r;
if (tree[y][]==x) l=;else l=;
r=-l;
if (y==k) k=x;
else
{
if (tree[z][]==y) tree[z][]=x;
else tree[z][]=x;
}
fath[x]=z;fath[y]=x;fath[tree[x][r]]=y;
tree[y][l]=tree[x][r];tree[x][r]=y;
pushup(y);pushup(x);
}
void splay(int x,int &k)
{
while (x!=k)
{
int y=fath[x],z=fath[y];
if (y!=k)
{
if ((tree[y][]==x)^(tree[z][]==y)) rotate(x,k);
else rotate(y,k);
}
rotate(x,k);
}
}
int get_pre(int x)
{
int ret=tree[x][];
while (tree[ret][])
ret=tree[ret][];
return ret;
}
int get_sub(int x)
{
int ret=tree[x][];
while (tree[ret][])
ret=tree[ret][];
return ret;
}
void delete_(int x)
{
splay(x,root);
int pre=get_pre(root);
int ls=tree[x][],rs=tree[x][];
root=ls;fath[ls]=fath[rs]=;splay(pre,root);
tree[root][]=rs;fath[rs]=root;pushup(root);
reset(x);
}
int find_kth(int now,int x)
{
int r=size[tree[now][]];
if (x<=r) return find_kth(tree[now][],x);
else if (x>r+) return find_kth(tree[now][],x-r-);
else
{
rr=now;
return now;
}
}
int get_rank(int x)
{
splay(x,root);
return size[tree[root][]];
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d",&a[i+]);
hash[a[i+]]=i+;
}
a[]=n+;a[n+]=n+;
build(root,,n+,);
for (int i=;i<=m;i++)
{
scanf("%s",s);
if (s[]=='T')
{
scanf("%d",&x);
delete_(hash[x]);
y=find_kth(root,);
splay(y,root);
int rs=tree[root][];
reset(root);
fath[root]=hash[x];fath[rs]=hash[x];tree[hash[x]][]=root;tree[hash[x]][]=rs;pushup(hash[x]);
root=hash[x];
splay((n+)>>,root);
}
else if (s[]=='B')
{
scanf("%d",&x);
delete_(hash[x]);
y=find_kth(root,n+);
splay(y,root);
int ls=tree[root][];
reset(root);
fath[root]=hash[x];fath[ls]=hash[x];tree[hash[x]][]=root;tree[hash[x]][]=ls;pushup(hash[x]);
root=hash[x];
splay((n+)>>,root);
}
else if (s[]=='I')
{
scanf("%d%d",&x,&y);
if (y==) continue;
else if (y==-)
{
int pre=get_pre(hash[x]);
sets(pre,hash[x]);
}
else
{
int sub=get_sub(hash[x]);
sets(hash[x],sub);
}
splay(hash[x],root);
}
else if (s[]=='A')
{
scanf("%d",&x);
printf("%d\n",get_rank(hash[x])-);
splay(hash[x],root);
}
else
{
rr=;
scanf("%d",&x);
printf("%d\n",val[find_kth(root,x+)]);
splay(rr,root);
}
}
return ;
}

BZOJ 1861 书架的更多相关文章

  1. BZOJ 1861书架

    小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引 ...

  2. [题解]bzoj 1861 Book 书架 - Splay

    1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1396  Solved: 803[Submit][Stat ...

  3. BZOJ 1861: [Zjoi2006]Book 书架

    1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1290  Solved: 740[Submit][Stat ...

  4. BZOJ 1861: [Zjoi2006]Book 书架 splay

    1861: [Zjoi2006]Book 书架 Description 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书 ...

  5. BZOJ 1861: [Zjoi2006]Book 书架 (splay)

    1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1453  Solved: 822[Submit][Stat ...

  6. BZOJ 1861: [Zjoi2006]Book 书架 | SPlay 板题

    #include<cstdio> #include<algorithm> #include<cstring> #define N 80010 #define whi ...

  7. BZOJ 1861 [Zjoi2006]Book 书架 ——Splay

    [题目分析] 模板题目. 首尾两个虚拟结点,十分方便操作. [代码] #include <cstdio> #include <cstring> #include <cma ...

  8. [bzoj 1861][zjoi2006] 书架

    传送门 Description 1. Top S--表示把编号为S的书放在最上面. 2. Bottom S--表示把编号为S的书放在最下面. 3. Insert S T--T∈{-1,0,1},若编号 ...

  9. bzoj 1861 treap

    思路:搞搞平衡树. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def ...

随机推荐

  1. SQL SERVER开窗函数

    作为一名开发人员来讲,我感觉在职场白混了好多年,可能是自己真的没有进取的精神吧,看了<程序员的SQL金典>这本电子书,真的让我学到了不少知识,真心喜欢这本电子书,书中讲解的内容比较好懂,也 ...

  2. PHP Zend Studio9.0怎么把代码搞成和服务器端的同步(就是直接在服务器端修改)

    Zend Studio 可以直接通过Remote System的方式直接连接服务器端的代码,就是可以直接修改服务器端的代码,不过修改的时间小心点,修改就会立即生效的. 选择Remote Systems ...

  3. cf div2 235 D

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  4. apache common-io.jar FileUtils

    //复制文件  void copyFile(File srcFile, File destFile)   //将文件内容转化为字符串 String readFileToString(File file ...

  5. 李洪强iOS开发之OC语言BLOCK和协议

    OC语言BLOCK和协议 一.BOLCK (一)简介 BLOCK是什么? 苹果推荐的类型,效率高,在运行中保存代码.用来封装和保存代码,有点像函数,BLOCK可以在任何时候执行. BOLCK和函数的相 ...

  6. hdu 3544 Alice's Game

    #include<stdio.h> int main() { int t,n; __int64 sum1,sum2; int i,j,a,b; scanf("%d",& ...

  7. 【mongoDB中级篇①】游标cursor

    简述 通俗的说,游标不是查询结果,可以理解为数据在遍历过程中的内部指针,其返回的是一个资源,或者说数据读取接口. 客户端通过对游标进行一些设置就能对查询结果进行有效地控制,如可以限制查询得到的结果数量 ...

  8. 无法嵌入互操作类型“ESRI.ArcGIS.Display.SimpleFillSymbolClass”。请改用适用的接口。

    无法嵌入互操作类型"ESRI.ArcGIS.Display.SimpleFillSymbolClass".请改用适用的接口. 对于这样的问题 先看这个错误所对应的引用时那个,比如这 ...

  9. 查看Linux版本系统信息方法汇总

    Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然.  1.# uname -a   (Linux查看版本当前操作系统内核信息)  Lin ...

  10. 深度神经网络如何看待你,论自拍What a Deep Neural Network thinks about your #selfie

    Convolutional Neural Networks are great: they recognize things, places and people in your personal p ...