嘟嘟嘟




[NOI2003]的其实就是一个板子……所以我就不说啥了。

唯一需要注意的是读入字符(哎……):题中说“中间可能有空格,请忽略”的意思是要在程序里特判掉,不是不管他……

输出的时候暴力中序遍历就行。

然后[AHOI2006]的只是多了一个区间翻转,然后输出单个字符,其实还是板子。
只不过读入特别坑,推荐看luogu的讨论里的读入。
以及可能有些乱七八糟的操作,得手动忽略……


[NOI2003]
```c++
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 2e6 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans = 10) write(x / 10);
putchar(x % 10 + '0');
}

char s[20], a[maxn];

int Cur = 0;

struct Tree

{

int ch[2], fa;

int siz; char c;

}t[maxn];

define ls t[now].ch[0]

define rs t[now].ch[1]

int root, tcnt = 0;

int st[maxn], top = 0;

In void _PrintTr(int now)

{

if(!now) return;

printf("no:%d val:%c ls:%c rs:%c\n", now, t[now].c, t[ls].c, t[rs].c);

_PrintTr(ls); _PrintTr(rs);

}

In void init() //完全手动初始化……

{

t[root = ++tcnt].c = '\('; t[tcnt].siz = 2;
t[++tcnt].c = '\)'; t[tcnt].siz = 1;

t[root].ch[1] = tcnt; t[tcnt].fa = root;

}

In void pushup(int now)

{

t[now].siz = t[ls].siz + t[rs].siz + 1;

}

In void rotate(int x)

{

int y = t[x].fa, z = t[y].fa, k = (t[y].ch[1] == x);

t[z].ch[t[z].ch[1] == y] = x; t[x].fa = z;

t[y].ch[k] = t[x].ch[k ^ 1]; t[t[y].ch[k]].fa = y;

t[x].ch[k ^ 1] = y; t[y].fa = x;

pushup(y), pushup(x);

}

In void splay(int x, int s)

{

while(t[x].fa != s)

{

int y = t[x].fa, z = t[y].fa;

if(z != s) rotate(((t[y].ch[0] == x) ^ (t[z].ch[0] == y)) ? x : y);

rotate(x);

}

if(!s) root = x;

}

In int Find(int k)

{

int now = root;

while(1)

{

if(t[ls].siz >= k) now = ls;

else if(t[ls].siz + 1 == k) return now;

else k -= (t[ls].siz + 1), now = rs;

}

}

In int split(int L, int R)

{

int a = Find(L), b = Find(R + 2);

splay(a, 0); splay(b, a);

return t[root].ch[1];

}

In int build(int L, int R, int fa)

{

if(L > R) return 0;

int mid = (L + R) >> 1, now = top ? st[top--] : ++tcnt;

t[now].fa = fa;

t[now].siz = 1; t[now].c = a[mid];

ls = build(L, mid - 1, now);

rs = build(mid + 1, R, now);

pushup(now);

return now;

}

In void update_in()

{

int n = read();

char x = getchar(); while(x < 32 || x > 126) x = getchar();

for(int i = 1; i <= n; ++i, x = getchar())

{

if(x < 32 || x > 126) {--i; continue;}

a[i] = x;

}

int tp = build(1, n, 0);

int a = Find(Cur + 1), b = Find(Cur + 2);

splay(a, 0); splay(b, a);

int now = t[root].ch[1];

t[now].ch[0] = tp; t[tp].fa = now;

pushup(now); pushup(root);

}

In void rec(int now)

{

if(!now) return;

rec(ls); rec(rs);

st[++top] = now;

}

In void update_del(int L, int R)

{

int now = split(L, R);

rec(t[now].ch[0]);

t[t[now].ch[0]].fa = 0; t[now].ch[0] = 0;

pushup(now); pushup(root);

}

In void print(int now)

{

if(!now) return;

print(ls);

putchar(t[now].c);

print(rs);

}

In void query(int L, int R)

{

int now = split(L, R);

print(t[now].ch[0]);

}

int main()

{

int T = read();

init();

while(T--)

{

scanf("%s", s);

if(s[0] == 'M') Cur = read();

else if(s[0] == 'I') update_in();

else if(s[0] == 'D')

{

int n = read();

update_del(Cur + 1, Cur + n);

}

else if(s[0] == 'G')

{

int n = read();

query(Cur + 1, Cur + n); enter;

}

else if(s[0] == 'P') Cur--;

else Cur++;

}

return 0;

}

</br>
[AHOI2006]
```c++
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 2e6 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} char s[20], a[maxn];
int Cur = 0;
struct Tree
{
int ch[2], fa;
int siz, rev; char c;
}t[maxn];
#define ls t[now].ch[0]
#define rs t[now].ch[1]
int root, tcnt = 0;
int st[maxn], top = 0; In void _PrintTr(int now)
{
if(!now) return;
printf("no:%d val:%c ls:%c rs:%c\n", now, t[now].c, t[ls].c, t[rs].c);
_PrintTr(ls); _PrintTr(rs);
} In void init()
{
t[root = ++tcnt].c = '$'; t[tcnt].siz = 2;
t[++tcnt].c = '$'; t[tcnt].siz = 1;
t[root].ch[1] = tcnt; t[tcnt].fa = root;
} In void c_rev(int now)
{
swap(ls, rs); t[now].rev ^= 1;
}
In void pushdown(int now)
{
if(t[now].rev)
{
if(ls) c_rev(ls);
if(rs) c_rev(rs);
t[now].rev = 0;
}
}
In void pushup(int now)
{
t[now].siz = t[ls].siz + t[rs].siz + 1;
}
In void rotate(int x)
{
int y = t[x].fa, z = t[y].fa, k = (t[y].ch[1] == x);
t[z].ch[t[z].ch[1] == y] = x; t[x].fa = z;
t[y].ch[k] = t[x].ch[k ^ 1]; t[t[y].ch[k]].fa = y;
t[x].ch[k ^ 1] = y; t[y].fa = x;
pushup(y), pushup(x);
}
In void splay(int x, int s)
{
while(t[x].fa != s)
{
int y = t[x].fa, z = t[y].fa;
if(z != s) rotate(((t[y].ch[0] == x) ^ (t[z].ch[0] == y)) ? x : y);
rotate(x);
}
if(!s) root = x;
}
In int Find(int k)
{
int now = root;
if(k > t[root].siz) {printf("ERR: %d %d\n", k, t[root].siz); exit(0);}
while(1)
{
pushdown(now);
if(t[ls].siz >= k) now = ls;
else if(t[ls].siz + 1 == k) return now;
else k -= (t[ls].siz + 1), now = rs;
}
}
In int split(int L, int R)
{
int a = Find(L), b = Find(R + 2);
splay(a, 0); splay(b, a);
pushdown(root); pushdown(t[root].ch[1]);
return t[root].ch[1];
}
In int build(int L, int R, int fa)
{
if(L > R) return 0;
int mid = (L + R) >> 1, now = top ? st[top--] : ++tcnt;
t[now].fa = fa; t[now].rev = 0;
t[now].siz = 1; t[now].c = a[mid];
ls = build(L, mid - 1, now);
rs = build(mid + 1, R, now);
pushup(now);
return now;
}
In void update_in()
{
int n = read();
char x;
for(int i = 1; i <= n; ++i)
{
x = getchar();
while(x < 32 || x > 126)
{
if(x == 10 || x == 13)
{
for(i = i; i <= n + 1; ++i) a[i] = 0;
break;
}
x = getchar();
}
a[i] = x;
}
int tp = build(1, n, 0);
int a = Find(Cur + 1), b = Find(Cur + 2);
splay(a, 0); splay(b, a);
pushdown(root); pushdown(t[root].ch[1]);
int now = t[root].ch[1];
t[now].ch[0] = tp; t[tp].fa = now;
pushup(now); pushup(root);
}
In void rec(int now)
{
if(!now) return;
rec(ls); rec(rs);
st[++top] = now;
}
In void update_del(int L, int R)
{
int now = split(L, R);
rec(t[now].ch[0]);
t[t[now].ch[0]].fa = 0; t[now].ch[0] = 0;
pushup(now); pushup(root);
}
In void update_rev(int L, int R)
{
int now = split(L, R);
c_rev(t[now].ch[0]);
pushup(now); pushup(root);
}
In char query(int x)
{
int now = Find(x + 1); splay(now, 0);
return t[root].c;
} int main()
{
int T = read();
init();
while(T--)
{
scanf("%s", s);
if(s[0] == 'M') Cur = read();
else if(s[0] == 'I') update_in();
else if(s[0] == 'D')
{
int n = read();
update_del(Cur + 1, Cur + n);
}
else if(s[0] == 'R')
{
int n = read();
update_rev(Cur + 1, Cur + n);
}
else if(s[0] == 'G')
{
putchar(query(Cur + 1)); enter;
}
else if(s[0] == 'P') Cur--;
else if(s[0] == 'N') Cur++;
}
return 0;
}

[NOI2003],[AHOI2006]文本编辑器的更多相关文章

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

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

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

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

  3. AHOI2006文本编辑器editor

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

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

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

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

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

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

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

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

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

  8. [AHOI2006] 文本编辑器editor

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

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

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

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

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

随机推荐

  1. shell | {}和()

    执行 bash -n xx.sh用于检测脚本语法是否有错误 bash -x xx.sh用于追踪执行 ${var} 用于限定变量名称的范围,并且支持通配符 $(cmd) shell会先执行括号的cmd, ...

  2. 数字证书及CA介绍

    数字证书及CA介绍 作者: 编程随想  发布时间: 2013-12-03 11:48  阅读: 95280 次  推荐: 69   原文链接   [收藏]   ★ 先说一个通俗的例子 考虑到证书体系的 ...

  3. Anaconda 安装、使用

    一.下载: 清华镜像:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 二.安装: 默认就行,安装路径最好换一下 三.配置环境变量: 控制面 ...

  4. [Hadoop异常处理] Namenode和Datanode都正常启动,但是web页面不显示

    异常 namenode和data都正常启动 但是web页面却不显示,都为零 解决办法一: 在hdfs-site.xml配置文件中,加入 <property> <name>dfs ...

  5. C# ACtiveMQ 收发数据

    1.下载ActiveMQ 官方网站下载地址:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.10.0-bin.zip,然后双 ...

  6. Strust2框架笔记01_XML配置_action编写

    目录 1.Struts2概述 1.1 什么是Struts2 1.2 Web层框架基于前端控制器模型设计 2. Struts2入门案例 2.1 Struts2的开发环境 2.2 解压开发包 2.3 创建 ...

  7. 【原】Dubbo 多版本号过渡

    之前发过一篇因为接口规范的问题导致其它端出现服务不可用的文章(http://www.cnblogs.com/zdd-java/p/8612763.html),然而最近在查阅了dubbo官方指南文档才知 ...

  8. js .map方法

    map这里的map不是“地图”的意思,而是指“映射”.[].map(); 基本用法跟forEach方法类似: array.map(callback,[ thisObject]); callback的参 ...

  9. sql server: Graphs, Trees, Hierarchies and Recursive Queries

    --------------------------------------------------------------------- -- Chapter 09 - Graphs, Trees, ...

  10. React Native中Mobx的使用

    从今天开始我们来搞搞状态管理可否,这几天没怎么写博客,因为被病魔战胜了,tmd,突然的降温让我不知所措,大家最近注意安全,毕竟年底了,查的严,呸,大家注意保暖 特别声明:写该文只是写一下用MobX的思 ...