写完维修数列 这不是水题嘛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. SAP computer之program counter

    Program counter The program is stored in memory with the first instruction at binary address 0000, t ...

  2. logical vs physical address

    Logical vs physical address  1) An address generated by the CPU is a logical address. Whereas, an ad ...

  3. 02 java学习安装jdk及其环境配置

    SUN公司1995年正式推出的一款语言 其实之前,Sun公司1991年,James Gosling等人就开始开发Oak语言,希望用于控制嵌入有效电视交换盒,1994年更名为Java,之前来自 与jav ...

  4. 分别用for循环,while do-while以及递归方法实现n的阶乘!

    分别用for循环,while do-while以及递归方法实现n的阶乘! 源码: package book;import java.util.Scanner;public class Access { ...

  5. BZOJ 2085 luogu P3502 [POI2010]Hamsters (KMP、Floyd、倍增)

    数组开小毁一生-- 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2085 这题在洛谷上有个条件是"互不包含",其实 ...

  6. mysql中的高级查询语句

    此随笔用到的数据全是来自  关于mysql中表关系的一些理解(一对一,一对多,多对多) 提及的    学院表,学生表,学生详情表,选课表,课程表 单标查询:(查看学生表的学生名单) select st ...

  7. Spring Web Flow实例教程

    目录: 参考文献 购物车用例 什么情况下可以使用 Spring Web Flow? 配置 Spring Web MVC 配置 Spring Web Flow 2.0 的基础 在购物车示例应用中配置 S ...

  8. 使用idea创建maven项目时 需要注意的问题

    截几张图来说明吧 上面的红色框如果不选中  将来创建的工程中没有webapp目录以及下面的子目录 选中之后  然后一直“下一步”  直到工程创建 但是我第一次按照正确的方式操作时  工程中并没有src ...

  9. orcale 基本查询(1)

    orcale 基本查询 查询当前用户下的所有表:  select * from tab; 查询表结构: desc 表名设置行宽: set linesize 120;设置列宽: 数值类型: col 列名 ...

  10. ExtJs之ExtJs.Model验证

    没有搞好,但知道意思和配置,并且好像4和3的没有兼容性语法,所以网上找了新语法才出来了点东东. <!DOCTYPE html> <html> <head> < ...