写完维修数列 这不是水题嘛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. CVPR2015深度学习回顾

    原文链接:http://www.csdn.net/article/2015-08-06/2825395 本文做了少量修改,仅作转载存贮,如有疑问或版权问题,请访问原作者或告知本人. CVPR可谓计算机 ...

  2. 【sqli-labs】 less10 GET - Blind - Time based. - Double quotes (基于时间的双引号盲注)

    这个和less9一样,单引号改完双引号就行了 http://localhost/sqli/Less-10/?id=1" and sleep(5)%23 5s后页面完成刷新 http://lo ...

  3. Labview学习笔记(二)

    一.编程基础 LABVIEW程序成为虚拟.仪器程序,简称VI,一个最基本的VI包括三个部分:前面板.程序框图和图标/连接端口. 1.前面板 在前面板窗口中,可以添加输入控件和显示控件,同时,可以用快捷 ...

  4. sql积累

    mysql 修改一列自增长 set @rownum=0; update a SET id = ( select @rownum := @rownum +1 as nid) WHERE id < ...

  5. Linux—Ubuntu14.0.5安装MySQL

    1.更新资援列表 sudo apt-get update 2.安装mysql的操作命令(下一步选中“Y”) sudo apt-get install mysql-server 3.输入MySQLroo ...

  6. reset清除所有浏览器默认样式

    温馨提示 reset 的目的不是清除浏览器的默认样式, 这仅是部分工作. 清除和重置是紧密不可分的.reset 的目的不是让默认样式在所有浏览器下一致, 而是减少默认样式有可能带来的问题.reset ...

  7. nyoj 547 优先队列

    #include<stdio.h> #include<string.h> #include<queue>//水杯盛水问题,用优先队列不断从最小的边缘开始 using ...

  8. SCU - 4117 - Discover

    先上题目: D - Discover Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit St ...

  9. 0709关于mysql优化思路【何登成】

    转自 http://isky000.com/database/mysql-performance-tuning-sql 优化目标 减少 IO 次数IO永远是数据库最容易瓶颈的地方,这是由数据库的职责所 ...

  10. Spring MVC-表单(Form)处理示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_form_handling.htm 说明:示例基于Spring MVC 4.1.6 ...