[BZOJ1507] [NOI2003] Editor (splay)
Description

Input
Output
输出文件editor.out的每行依次对应输入文件中每条GET指令的输出。
Sample Input
Insert 26
abcdefghijklmnop
qrstuv wxy
Move 15
Delete 11
Move 5
Insert 1
^
Next
Insert 1
_
Next
Next
Insert 4
.\/.
Get 4
Prev
Insert 1
^
Move 0
Get 22
Sample Output
abcde^_^f.\/.ghijklmno
HINT
Source
Solution
splay的区间操作。
#include <bits/stdc++.h>
using namespace std;
struct spaly
{
char key;
int siz, fa, c[];
}a[];
char inss[];
int ptot; void push_up(int k)
{
a[k].siz = a[a[k].c[]].siz + a[a[k].c[]].siz + ;
} void rotate(int &k, int x)
{
int y = a[x].fa, z = a[y].fa;
int dy = a[y].c[] == x, dz = a[z].c[] == y;
if(k == y) k = x, a[x].fa = z;
else a[z].c[dz] = x, a[x].fa = z;
a[y].c[dy] = a[x].c[!dy], a[a[x].c[!dy]].fa = y;
a[x].c[!dy] = y, a[y].fa = x;
push_up(y);
} void splay(int &k, int x)
{
while(k != x)
{
int y = a[x].fa, z = a[y].fa;
if(k != y)
if(a[y].c[] == x ^ a[z].c[] == y) rotate(k, x);
else rotate(k, y);
rotate(k, x);
}
push_up(x);
} int find(int k, int x)
{
if(!k || x == a[a[k].c[]].siz + ) return k;
if(x <= a[a[k].c[]].siz) return find(a[k].c[], x);
return find(a[k].c[], x - a[a[k].c[]].siz - );
} void build(int &k, int fa, int i, int m)
{
if(i == m) return;
k = ++ptot, a[k].fa = fa, a[k].key = inss[i];
build(a[k].c[], k, i + , m);
push_up(k);
} void printf(int k)
{
if(!k) return;
printf(a[k].c[]), printf("%c", a[k].key), printf(a[k].c[]);
} int main()
{
int n, m, root = , pos = , ctot = ;
char op[];
scanf("%d", &n), ptot = ;
a[].c[] = , a[].siz = , a[].siz = , a[].fa = ;
while(n--)
{
scanf("%s", op);
if(op[] == 'M') scanf("%d", &pos);
if(op[] == 'I')
{
scanf("%d", &m), ctot += m;
for(int i = ; i < m; i++)
{
inss[i] = getchar();
if(inss[i] < || inss[i] > ) i--;
}
splay(root, find(root, pos + ));
splay(a[root].c[], find(root, pos + ));
build(a[a[root].c[]].c[], a[root].c[], , m);
push_up(a[root].c[]), push_up(root);
}
if(op[] == 'D')
{
scanf("%d", &m), m = min(m, ctot - pos);
splay(root, find(root, pos + ));
splay(a[root].c[], find(root, pos + m + ));
a[a[root].c[]].c[] = , ctot -= m;
push_up(a[root].c[]), push_up(root);
}
if(op[] == 'G')
{
scanf("%d", &m), m = min(m, ctot - pos);
splay(root, find(root, pos + ));
splay(a[root].c[], find(root, pos + m + ));
printf(a[a[root].c[]].c[]), puts("");
}
if(op[] == 'P') pos--;
if(op[] == 'N') pos++;
}
return ;
}
[BZOJ1507] [NOI2003] Editor (splay)的更多相关文章
- BZOJ1507 [NOI2003]Editor 【splay】
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MB Submit: 4129 Solved: 1660 [Submit][St ...
- BZOJ1507 [NOI2003]Editor
是一道裸的Splay(反正我不会Splay,快嘲笑我!) 只需要维护在数列上加点删点操作即可,不会写Splay的渣渣只好Orz iwtwiioi大神一下了.(后来发现程序直接抄来了...) 就当我的第 ...
- BZOJ 1507 NOI2003 Editor Splay
题目大意: 1.将光标移动到某一位置 2.在光标后插入一段字符串 3.删除光标后的一段字符 4.输出光标后的一段字符 5.光标-- 6.光标++ 和1269非常像的一道题,只是弱多了 几个问题须要注意 ...
- 【bzoj1507】[NOI2003]Editor /【bzoj1269】[AHOI2006]文本编辑器editor Splay
[bzoj1507][NOI2003]Editor 题目描述 输入 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中 ...
- 【BZOJ1269/1507】[AHOI2006]文本编辑器editor Splay
[BZOJ1269][AHOI2006]文本编辑器editor Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目 ...
- BZOJ_1507_Editor_[NOI2003]_(Splay)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1507 简单区间操作的模板题 1507: [NOI2003]Editor Time Limit: ...
- BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor
BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor 题意: 分析: splay模拟即可 注意1507的读入格式 ...
- 【BZOJ-1507】Editor 块状链表
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3397 Solved: 1360[Submit][Stat ...
- 1507: [NOI2003]Editor(块状链表)
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4157 Solved: 1677[Submit][Stat ...
随机推荐
- 自定义状态栏的颜色及navigation的title颜色
1.在info.plist中添加View controller-based status bar appearance,值为NO 2.在设置状态栏的地方添加代码 [[UIApplication sha ...
- python学习:函数传参数
#!/usr/bin/python import sys def isNum(s): for i in s: if i in '0123456789': ...
- CentOS利用Nginx+Docker部署.netcore应用
安装docker 官方文档https://docs.docker.com/engine/installation/linux/docker-ce/centos/ [root@sn ~]# yum re ...
- SDK编程之多线程编程
本课中,我们将学习如何进行多线程编程.另外我们还将学习如何在不同的线程间进行通信. 理论:前一课中,我们学习了进程,其中讲到每一个进程至少要有一个主线程.这个线程其实是进程执行的一条线索,除此主线程外 ...
- CentOs 7 中安装tomcat8
1,下载tomcat8.0 进入tomcat的下载地址:http://tomcat.apache.org/download-80.cgi 2,上传到linux服务器 cd /usr/local/jav ...
- ASP.NET Core 使用 URL Rewrite 中间件实现 HTTP 重定向到 HTTPS
在传统 ASP.NET 程序中,我们可以通过配置 IIS 的“URL 重写”功能实现将 HTTP 请求重定向为 HTTPS .但是该方法在 ASP.NET Core 应用中不再工作.在 ASP.NET ...
- mybatis3:Invalid bound statement (not found)
最近在玩ssm框架搭建,突然发现最后的时候mybaits和SpringMvc进行整合的时候出现错误 Invalid bound statement (not found) 这个错误有可能出现在以下几个 ...
- 老男孩Python全栈开发(92天全)视频教程 自学笔记15
day15课程内容: 高阶函数 1.函数名可以进行赋值 2.函数名可以作为参数,也可以作为函数的返回值 def f(): print("高阶函数")def bar(a,b,c): ...
- SpringBoot,Security4, redis共享session,分布式SESSION并发控制,同账号只能登录一次
由于集成了spring session ,redis 共享session,导致SpringSecurity单节点的session并发控制失效, springSession 号称 无缝整合httpses ...
- alsa声卡分析alsa-utils调用过程
如何分析tinyplay 播放音频和tinymix的过程?需要相应的工具来支持追查: 一.利用strace工具分析tinyplay和tinymix: strace -o tinyplay.log ti ...