题目大意:

1.将光标移动到某一位置

2.在光标后插入一段字符串

3.删除光标后的一段字符

4.输出光标后的一段字符

5.光标--

6.光标++

和1269非常像的一道题,只是弱多了

几个问题须要注意:

1.插入的字符串中间竟然会有回车!

。没办法了,仅仅能逐个字符进行读入。一旦读到'\n'或者'\r'就又一次读入

2.题目描写叙述中说Delete和Get操作后面一定会有足够的字符 纯属放P 连例子都没有足够的字符用来删除 所以删除时要和字符串长度取一个最小值

然后就水水地过去了~

30%达成 今天是不是能够歇息了0.0 妈蛋先把圆上的整点搞过去再说

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct abcd{
abcd *fa,*ls,*rs;
char c;
int siz;
bool rev_mark;
abcd (char C);
void Push_Up();
}*null=new abcd(0),*root=null;
abcd :: abcd(char C)
{
fa=ls=rs=null;
c=C;
siz=C?1:0;
rev_mark=0;
}
void abcd :: Push_Up()
{
siz=ls->siz+rs->siz+1;
}
void Zig(abcd *x)
{
abcd *y=x->fa;
y->ls=x->rs;
x->rs->fa=y;
x->rs=y;
x->fa=y->fa;
if(y==y->fa->ls)
y->fa->ls=x;
else if(y==y->fa->rs)
y->fa->rs=x;
y->fa=x;
y->Push_Up();
if(y==root)
root=x;
}
void Zag(abcd *x)
{
abcd *y=x->fa;
y->rs=x->ls;
x->ls->fa=y;
x->ls=y;
x->fa=y->fa;
if(y==y->fa->ls)
y->fa->ls=x;
else if(y==y->fa->rs)
y->fa->rs=x;
y->fa=x;
y->Push_Up();
if(y==root)
root=x;
}
void Splay(abcd *x,abcd *Tar)
{
while(1)
{
abcd *y=x->fa,*z=y->fa;
if(y==Tar)
break ;
if(z==Tar)
{
if(x==y->ls)
Zig(x);
else
Zag(x);
break;
}
if(x==y->ls)
{
if(y==z->ls)
Zig(y);
Zig(x);
}
else
{
if(y==z->rs)
Zag(y);
Zag(x);
}
}
x->Push_Up();
}
void Find(abcd *x,int y,abcd *z)
{
while(1)
{
if(y<=x->ls->siz)
x=x->ls;
else
{
y-=x->ls->siz;
if(y==1)
break;
y--;
x=x->rs;
}
}
Splay(x,z);
}
void Output(abcd *x)
{
if(x==null)
return ;
Output(x->ls);
putchar(x->c);
Output(x->rs);
}
char s[1<<21];
void Build_Tree(abcd *&x,int l,int r)
{
if(l>r)
return ;
int mid=l+r>>1;
x=new abcd(s[mid]);
Build_Tree(x->ls,l,mid-1);
Build_Tree(x->rs,mid+1,r);
if(x->ls!=null)
x->ls->fa=x;
if(x->rs!=null)
x->rs->fa=x;
x->Push_Up();
}
int cursor,m;
int main()
{
int i,j,x;
char p[100];
cin>>m;
{
root=new abcd('\n');
root->rs=new abcd('\n');
root->rs->fa=root;
root->Push_Up();
}
for(i=1;i<=m;i++)
{
scanf("%s",p);
if(p[0]=='M')
scanf("%d",&cursor);
else if(p[0]=='I')
{
scanf("%d",&x);
for(j=0;j<x;j++)
{
do s[j]=getchar(); while(s[j]<32);
}
Find(root,cursor+1,null);
Find(root,cursor+2,root);
Build_Tree(root->rs->ls,0,x-1);
root->rs->ls->fa=root->rs;
root->rs->Push_Up();
root->Push_Up();
}
else if(p[0]=='D')
{
scanf("%d",&x);
Find(root,cursor+1,null);
Find(root,min(cursor+x+2,root->siz),root);
root->rs->ls=null;
root->rs->Push_Up();
root->Push_Up();
}
else if(p[0]=='G')
{
scanf("%d",&x);
Find(root,cursor+1,null);
Find(root,min(cursor+x+2,root->siz),root);
Output(root->rs->ls);
puts("");
}
else if(p[0]=='P')
cursor--;
else
cursor++;
}
}

BZOJ 1507 NOI2003 Editor Splay的更多相关文章

  1. BZOJ 1507 [NOI2003]Editor

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

  2. 1507: [NOI2003]Editor(块状链表)

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 4157  Solved: 1677[Submit][Stat ...

  3. 1507: [NOI2003]Editor

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 3535  Solved: 1435 [Submit][St ...

  4. 【BZOJ】1507: [NOI2003]Editor(Splay)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1507 当练splay模板了,发现wjmzbmr的splay写得异常简介,学习了.orzzzzzzzz ...

  5. BZOI 1507 [NOI2003] Editor

    Background After trying to solve problem EDIT1(Editor) and being ****ed by Brainf**k, Blue Mary deci ...

  6. [BZOJ1507] [NOI2003] Editor (splay)

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

  7. BZOJ1507 [NOI2003]Editor 【splay】

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 4129  Solved: 1660 [Submit][St ...

  8. BZOJ_1507_Editor_[NOI2003]_(Splay)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1507 简单区间操作的模板题 1507: [NOI2003]Editor Time Limit: ...

  9. BZOJ 1269: [AHOI2006]文本编辑器editor( splay )

    splay..( BZOJ 1507 题目基本相同..双倍经验 ) ------------------------------------------------------------------ ...

随机推荐

  1. java解析json文件(省,市,区)

    [{"code":"11","name":"北京市"},{"code":"12" ...

  2. 紫书 例题 10-10 UVa 10491(概率计算)

    公式很好推,表示被高中生物遗传概率计算虐过的人 这个公式简直不需要动脑 #include<cstdio> using namespace std; int main() { double ...

  3. Redis序列化存储Java集合List等自定义类型

    在"Redis学习总结和相关资料"http://blog.csdn.net/fansunion/article/details/49278209 这篇文章中,对Redis做了总体的 ...

  4. Spring Boot学习总结(2)——Spring Boot整合Jsp

    怎么使用jsp上面起了疑问,查阅了多方资料,找到过其他人的博客的描述,也找到了spring在github上的给出的例子,看完后稍微改动后成功 整合jsp,于是决定将整合过程记载下来. 无论使用的是那种 ...

  5. 赋值、复制构造函数和构造函数 & 异常安全的赋值

    异常安全的赋值 需要注意,复制赋值和复制构造,相兼容. 赋值时候,要带上自检查.

  6. Android Volley 具体解释 Google公布的一套用于网络通信的工具库

    下载地址:git clone https://android.googlesource.com/platform/frameworks/volley 或 : https://github.com/mc ...

  7. elasticsearch搜索类型简单介绍

    简单搜索 GET请求很easy--你能轻松获取你想要的文档.让我们来进一步尝试一些东西.比方简单的搜索! 我们尝试一个最简单的搜索所有员工的请求: GET /megacorp/employee/_se ...

  8. Id选择器和Class选择器

    http://www.runoob.com/css/css-id-class.html http://www.w3school.com.cn/css/css_syntax_id_selector.as ...

  9. 水 hdu5208 2015-04-20 21:03 36人阅读 评论(0) 收藏

    题意: 选择数列中两个数,使得最大公约数最大 分析: 类似筛选法,因为数值不大,可以用b[i]计算i是多少个数的因子.最后取最大的i即可. #include <bits/stdc++.h> ...

  10. 是时候抛弃web.xml了?

    你是否再为配置文件web.xml容易出错而烦恼?是否为web.xml文件存放位置而不知所措?是否为web.xml为什么要这样配?怎么才能更好的配置web.xml而烦恼?那么一种新的方式出现了: spr ...