题目

多了区间翻转,之后没了

区间翻转的标记记得在\(kth\)的时候下传

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 2100005
#define re register
int n,m,root,len,pos=1;
char val[maxn],S[maxn],opt[15];
int fa[maxn],sz[maxn],ch[maxn][2],rev[maxn];
inline void pushup(int x) {sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+1;}
inline void pushdown(int x) {
if(!rev[x]) return;
std::swap(ch[ch[x][0]][0],ch[ch[x][0]][1]);
std::swap(ch[ch[x][1]][0],ch[ch[x][1]][1]);
rev[x]=0,rev[ch[x][0]]^=1,rev[ch[x][1]]^=1;
}
inline void rotate(int x) {
int y=fa[x],z=fa[y],k=ch[y][1]==x,w=ch[x][k^1];
ch[z][ch[z][1]==y]=x;ch[x][k^1]=y;ch[y][k]=w;
pushup(y),pushup(x),fa[w]=y,fa[y]=x,fa[x]=z;
}
inline void splay(int x,int goal) {
while(fa[x]!=goal) {
int y=fa[x];
if(fa[y]!=goal) rotate((ch[y][1]==x)^(ch[fa[y]][1]==y)?x:y);
rotate(x);
}
if(!goal) root=x;
}
inline int kth(int now) {
int x=root;
while(1) {
pushdown(x);
if(sz[ch[x][0]]+1==now) return x;
if(sz[ch[x][0]]>=now) x=ch[x][0];
else now-=sz[ch[x][0]]+1,x=ch[x][1];
}
}
int build(int x,int y,int f) {
if(x>y) return 0;
if(x==y) {
fa[++m]=f,sz[m]=1,val[m]=S[x];
return m;
}
int mid=x+y>>1,rt=++m;
fa[rt]=f,val[rt]=S[mid];
ch[rt][0]=build(x,mid-1,rt),ch[rt][1]=build(mid+1,y,rt);pushup(rt);
return rt;
}
int main()
{
scanf("%d",&n);
root=1,sz[1]=2,ch[1][1]=2,sz[2]=1,fa[2]=1;m=2;
while(n--) {
scanf("%s",opt);
if(opt[0]=='M') scanf("%d",&pos),pos++;
if(opt[0]=='P') pos--;
if(opt[0]=='N') pos++;
if(opt[0]=='I') {
scanf("%d",&len);S[0]=getchar();
for(re int i=1;i<=len;i++) S[i]=getchar();
int aa=kth(pos),bb=kth(pos+1);
splay(aa,0),splay(bb,aa);
int t=ch[root][1],rt=build(1,len,t);
ch[t][0]=rt;pushup(t);splay(t,0);
}
if(opt[0]=='D') {
scanf("%d",&len);
int aa=kth(pos),bb=kth(pos+len+1);
splay(aa,0),splay(bb,aa);
ch[ch[root][1]][0]=0;pushup(ch[root][1]);splay(ch[root][1],0);
}
if(opt[0]=='G') {
int aa=kth(pos),bb=kth(pos+2);
splay(aa,0),splay(bb,aa);
putchar(val[ch[ch[root][1]][0]]);
if(val[ch[ch[root][1]][0]]!=10) putchar(10);
}
if(opt[0]=='R') {
scanf("%d",&len);
int aa=kth(pos),bb=kth(pos+len+1);
splay(aa,0),splay(bb,aa);
int t=ch[ch[root][1]][0];
std::swap(ch[t][1],ch[t][0]),rev[t]^=1;
}
}
return 0;
}

【[AHOI2006]文本编辑器】的更多相关文章

  1. AHOI2006文本编辑器editor

    1269: [AHOI2006]文本编辑器editor Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1885  Solved: 683[Submit ...

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

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

  3. BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor

    BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor 题意: 分析: splay模拟即可 注意1507的读入格式 ...

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

    1269: [AHOI2006]文本编辑器editor Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1213  Solved: 454[Submit ...

  5. 【BZOJ1269/1507】[AHOI2006]文本编辑器editor Splay

    [BZOJ1269][AHOI2006]文本编辑器editor Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目 ...

  6. 【bzoj1507】[NOI2003]Editor /【bzoj1269】[AHOI2006]文本编辑器editor Splay

    [bzoj1507][NOI2003]Editor 题目描述 输入 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中 ...

  7. BZOJ1269 [AHOI2006]文本编辑器editor 【82行splay】

    1269: [AHOI2006]文本编辑器editor Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 4633  Solved: 1782 [Sub ...

  8. [bzoj1269][AHOI2006文本编辑器editor] (splay模版题 or pb_ds [rope]大法)

    Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对“文本编辑器”做了一个抽象的定义:   文本:由0个或 ...

  9. Bzoj1269 [AHOI2006]文本编辑器editor

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3678  Solved: 1380 Description 这些日子,可可不和卡卡一起玩了,原来可可正 ...

  10. 【BZOJ】1269: [AHOI2006]文本编辑器editor(Splay)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1269 这题RE2次啊,好不爽啊,我一直以为是splay的问题,其实是数组开小了......(我老犯这 ...

随机推荐

  1. spark on yarn模式里需要有时手工释放linux内存

    为什么要提出这个问题? spark跑YARN模式或Client模式提交任务不成功(application state: ACCEPTED) 然后执行 [spark@master spark--bin- ...

  2. Git~分支真的很轻

    轻,让人觉得很爽 所有源代码管理工具都有管理分支的功能,git当然也不例外,而且git的分支是非常轻的,不像tfs,svn那样,复制一大堆代码,git只记录变化的内容,有本地分支与远程分支之分,原则上 ...

  3. PHP中break及continue两个流程控制指令解析

    <?php $arr = array( 'a' => '0a0', 'b' => '0b0', 'c' => '0c0', 'd' => '0d0', 'e' => ...

  4. Nginx实践:(2) Nginx语法之localtion

    1. 概念 location是根据uri进行不同的定位.在虚拟主机的配置中,是必不可少的.location可以将网站的不同部分,定位到不同的处理方式上. location语法格式如下: locatio ...

  5. 代码重构----使用java有限状态机来消除太多的if else判断

    1. 状态机基本概念 http://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90%E7%8A%B6%E6%80%81%E6%9C%BA 状态存储关于过去的信息,就是 ...

  6. JS常用的设计模式(2)——简单工厂模式

    简单工厂模式是由一个方法来决定到底要创建哪个类的实例, 而这些实例经常都拥有相同的接口. 这种模式主要用在所实例化的类型在编译期并不能确定, 而是在执行期决定的情况. 说的通俗点,就像公司茶水间的饮料 ...

  7. BulletedList用途

    1.用作最普通的信息显示(列表方式) 2.制作导航条 BulletedList3中模式 1.Text 文本 2.HyperLink 连接 2.LinkButton 按钮 BulletedList 导航 ...

  8. JavaScript typeof运算符和数据类型

    // js有6种数据类型:Undefined.Null.Boolean.String.Number.Object //(01)typeof console.log(typeof undefined); ...

  9. mybatis一对多映射

    场景: A:SecControlRulePojo.java B:SecControlSubRulePojo C:SecControlSubRuleManyPojo 实体A中包含List<B> ...

  10. mpvue自定义化后台富文本样式

    最近公司写小程序开始换框架了,之前用wepy,现在用mpvue. mpvue是基于vue的写法来开发微信小程序.虽然不完全和vue一样,但是大致和vue一样,所以基本开发上是上手很快的. 现在项目进程 ...