[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 ...
随机推荐
- Go语言极速入门手册
Github: https://github.com/coderzh/CodeTips /* gotips_test.go: Golang速学速查速用代码手册 Source: github.com/c ...
- IDA学习笔记 函数调用约定
stdcall和cdecl: stdcall和cdecl 压栈方向都是从右到左 区别在于c约定是调用方在函数返回后add esp,n指令清除堆栈中的参数,而stdcall在被调函数内使用ret n来清 ...
- easyui+ajax获取同表关联的数据
easyui是我们常用的前端框架之一,easyui的使用使得前端页面更加美观.为了能够使用combobox,ajax必须同步. 该小程序是使用ssm框架,对数据库的数据进行查询,所以url对应着map ...
- Shiro报错-[org.apache.shiro.mgt.AbstractRememberMeManager] - There was a failure while trying to retrieve remembered principals.
2017-04-08 11:55:33,010 WARN [org.apache.shiro.mgt.AbstractRememberMeManager] - There was a failure ...
- shiro笔记-AuthenticatingRealm和AuthorizingRealm关系
AuthenticatingRealm-------->用于认证方法的Realm AuthorizingRealm--------->用于授权和认证的realm一般使用这个 Authori ...
- js创建数组的三个方式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Web API 之承载宿主IIS,SelfHost,OwinSelfHost
Asp.Net WebAPI这个大家应该都不陌生,在我的理解范围中就是数据提供和交换的一个方式,相比与WCF,WS而言,更加的简单轻量,但是在部署web Api的时候,一般往往需要与a ...
- iOS——系统提供的dispatch方法
// 后台执行: dispatch_async(dispatch_get_global_queue(0,0), ^{ // something }); // 主线程执行: dispatch_async ...
- FZU - 2150 bfs [kuangbin带你飞]专题一
题意:两个人玩很变态的游戏,将一个草坪的某两个点点燃,点燃的草坪可以向上下左右四个方向扩散,问能否将整块草坪上面的草都点燃.如果能,输出最短时间(^_^他们就能玩更变态的游戏了),如果不能,输出-1. ...
- npm http-server Dockerfile alpine 微容器,袖珍体积,解决时区问题
前端写得少,但是前端技术的思想也是非常有学习的价值,用VUE写了几个手机form页面,体验了一番spa,用docker部署也是非常简单 直接docker pull node 676M体积.不能忍. ...