写完维修数列 这不是水题嘛233333

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=5000050;
int n,pos=1,ch[N][2],fa[N],size[N],root,xx,cnt;
char op[15],ins[N],v[N];
void push_up(int x){size[x]=size[ch[x][0]]+size[ch[x][1]]+1;}
void rotate(int p){
int q=fa[p],y=fa[q],f=(ch[q][1]==p);
ch[q][f]=ch[p][!f],fa[ch[q][f]]=q;
ch[p][!f]=q,fa[q]=p,fa[p]=y;
if(y)ch[y][ch[y][1]==q]=p;
push_up(q);
}
void splay(int x,int tp){
for(int y;y=fa[x];rotate(x)){
if(y==tp)break;
if(fa[y]!=tp){
if((ch[y][0]==x)^(ch[fa[y]][0]==y))rotate(x);
else rotate(y);
}
}push_up(x);
if(!tp)root=x;
}
int find(int x,int sz){
if(size[ch[x][0]]+1==sz)return x;
else if(size[ch[x][0]]>=sz)return find(ch[x][0],sz);
else return find(ch[x][1],sz-size[ch[x][0]]-1);
}
int build(int l,int r,int father){
if(l>r)return 0;
int pos=++cnt;
if(l==r){
size[pos]=1;
fa[pos]=father;
v[pos]=ins[l];
return pos;
}
int mid=(l+r)>>1;
ch[pos][0]=build(l,mid-1,pos);
fa[pos]=father;v[pos]=ins[mid];
ch[pos][1]=build(mid+1,r,pos);
push_up(pos);
return pos;
}
void check(int x){
if(ch[x][0])check(ch[x][0]);
printf("%c",v[x]);
if(ch[x][1])check(ch[x][1]);
}
int main(){
scanf("%d",&n);
root=1,size[1]=2,ch[1][0]=2,size[2]=1,fa[2]=1,cnt=2;
for(int i=1;i<=n;i++){
scanf("%s",op);
if(op[0]=='I'){
int fx=find(root,pos),fy=find(root,pos+1);
splay(fx,0),splay(fy,fx);
scanf("%d",&xx);
for(int j=1;j<=xx;j++)
while(scanf("%c",&ins[j]),ins[j]<32);
ch[fy][0]=build(1,xx,fy);
push_up(fy),push_up(fx);
// check(root);
}
else if(op[0]=='M')scanf("%d",&pos),pos++;
else if(op[0]=='P')pos--;
else if(op[0]=='N')pos++;
else if(op[0]=='D'){
scanf("%d",&xx);
xx=min(size[root],xx+pos+1);
int fx=find(root,pos),fy=find(root,xx);
splay(fx,0),splay(fy,fx);
ch[fy][0]=0,push_up(fy),push_up(fx);
}
else{
scanf("%d",&xx);
int fx=find(root,pos),fy=find(root,min(pos+xx+1,size[root]));
splay(fx,0),splay(fy,fx);
check(ch[fy][0]),puts("");
}
}
}

BZOJ 1507 splay的更多相关文章

  1. bzoj 1269 bzoj 1507 Splay处理文本信息

    bzoj 1269 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1269 大致思路: 用splay维护整个文本信息,splay树的中序遍历即为 ...

  2. 【BZOJ 1507】【NOI 2003】&【Tyvj P2388】Editor 块状链表模板题

    2016-06-18 当时关于块状链表的想法是错误的,之前维护的是一个动态的$\sqrt{n}$,所以常数巨大,今天才知道原因TwT,请不要参照这个程序为模板!!! 模板题水啊水~~~ 第一次写块状链 ...

  3. BZOJ 1507 NOI2003 Editor Splay

    题目大意: 1.将光标移动到某一位置 2.在光标后插入一段字符串 3.删除光标后的一段字符 4.输出光标后的一段字符 5.光标-- 6.光标++ 和1269非常像的一道题,只是弱多了 几个问题须要注意 ...

  4. BZOJ 1507 Editor

    Description Input 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中可能会插入一些回车符,请忽略掉它 ...

  5. bzoj 3506 && bzoj 1552 splay

    查最小值,删除,翻转... 显然splay啊... #include<iostream> #include<cstdio> #include<algorithm> ...

  6. bzoj 1014 splay维护hash值

    被后缀三人组虐了一下午,写道水题愉悦身心. 题很裸,求lcq时二分下答案就行了,写的不优美会被卡时. (写题时精神恍惚,不知不觉写了快两百行...竟然调都没调就A了...我还是继续看后缀自动机吧... ...

  7. bzoj 1503 splay

    因为是整体加减,所以直接记录在外面. #include<iostream> #include<cstdio> #include<cstring> #include& ...

  8. bzoj 3224 splay模板题4

    再刷水题我就废了... #include<iostream> #include<cstdio> #include<algorithm> #include<cs ...

  9. bzoj 3223 splay模板题3

    水题...貌似理解splay怎么维护数列了... 每个点维护一个size,它的位置就是它的size,区间翻转的话可以打标记,find的时候push_down,交换左右子树. #include<i ...

随机推荐

  1. 使用Visio—UML画类图

    在一个VS工程中,由于类的个数较多,而参数描述不是特别清晰.若此工程的生命周期较长,则有必要对工程进行完整分析,给出完整的文档.需要画出类图,并对每个成员进行详细描述. 一.画出类图 在VIsio中, ...

  2. Mac下php连接mysql数据库失败解决办法

    通过phpmyadmin连接mysql成功,但是通过php连接数据库失败,执行如下php语句 ? 1 @mysql_connect("localhost","root&q ...

  3. 【sqli-labs】 less4 GET - Error based - Double Quotes - String (基于错误的GET双引号字符型注入)

    提交id参数 加' http://localhost/sqli/Less-4/?id=1' 页面正常,添加" http://localhost/sqli/Less-4/?id=1" ...

  4. Mysql正则

    摘自:http://www.runoob.com/mysql/mysql-regexp.html 模式 描述 ^ 匹配输入字符串的开始位置.如果设置了 RegExp 对象的 Multiline 属性, ...

  5. 11.03 在外链接中用OR逻辑

    select e.ename,d.deptno,d.dname,d.locfrom dept d left join emp e on(d.deptno = e.deptnoand (e.deptno ...

  6. HDU_2149_基础博弈sg函数

    Public Sale Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. POJ_3020_最小路径覆盖

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8721   Accepted: 4330 ...

  8. Cache-Control官方文档

    https://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-25#page-21 5.2. Cache-Control The "Cach ...

  9. Linux 之secureCRT连接SSH

    1.登陆linux系统,打开终端命令.输入 rpm -qa |grep ssh 查找当前系统是否已经安装. 2.如果没有安装SSH软件包,可以通过yum  或rpm安装包进行安装. .3.安装好了之后 ...

  10. kipmi0进程单核CPU100%的解决办法

    top查看服务器进程,发现有个kipmi0的进程竟然CPU的单核占用高达100%,而且居高不下. 于是上网搜了搜大家的说法了给出的链接,大概意思是一个固件问题,可以通过修改文件来解决. 专业的解释地址 ...