BZOJ1507 [NOI2003]Editor
是一道裸的Splay(反正我不会Splay,快嘲笑我!)
只需要维护在数列上加点删点操作即可,不会写Splay的渣渣只好Orz iwtwiioi大神一下了。(后来发现程序直接抄来了。。。)
就当我的第一个Splay程序吧。
/**************************************************************
Problem: 1507
User: rausen
Language: C++
Result: Accepted
Time:2560 ms
Memory:43860 kb
****************************************************************/ #include <cstdio>
#include <cstring> using namespace std;
char strI[]; struct Splay{
struct node{
node *son[], *fa;
char key;
int size;
node(){
son[] = son[] = fa = NULL;
size = key = ;
}
void pushup(){
size = son[] -> size + son[] -> size + ;
} bool d(){
return this == fa -> son[];
} void setc(node *c, int d){
son[d] = c;
c -> fa = this;
}
} * null, *root; Splay(){
null = new node;
root = null;
root = newnode();
node *t = newnode();
root -> setc(t, );
root -> pushup();
} node *newnode(char K){
node *res = new node;
res -> son[] = res -> son[] = res -> fa = null;
res -> key = K, res -> size = ;
return res;
} void rotate(node *r){
node *fa = r -> fa;
bool d = r -> d();
fa -> fa -> setc(r, fa -> d());
fa -> setc(r -> son[!d], d);
r -> setc(fa, !d);
fa -> pushup();
if (fa == root) root = r;
} void splay(node *r, node *X){
while (r -> fa != X){
if (r -> fa -> fa == X) rotate(r);
else r -> d() == r -> fa -> d() ? (rotate(r -> fa), rotate(r)) : (rotate(r), rotate(r));
}
r -> pushup();
} node *sel(int k){
int s;
for(node *t = root; ;){
s = t -> son[] -> size;
if (s == k) return t;
t = t -> son[k > s];
if (k > s) k -= s + ;
}
} node *getrange(int l, int r){
node *left = sel(l); splay(left, null);
node *right = sel(r); splay(right, left);
return right;
} void insert(int w, int cur){
node *t = getrange(w, w + );
t -> setc(build(, cur), );
t -> pushup();
splay(t, null);
} void remove(int w, int n){
node *t = getrange(w, w + n + );
t -> setc(null, );
t -> pushup();
splay(t, null);
} node *build(int l, int r){
if (l >= r) return null;
int m = (l + r) >> ;
node *t = newnode(strI[m]);
t -> setc(build(l, m), );
t -> setc(build(m + , r), );
t -> pushup();
return t;
} void print(node *r){
if (r == null) return;
print(r -> son[]);
printf("%c", r -> key);
print(r -> son[]);
} void print(int w, int n){
node *t = getrange(w, w + n + );
print(t -> son[]);
printf("\n");
}
} splay; char s[]; int main(){
int n, T, cur, w = ;
scanf("%d", &T);
while (T--){
scanf("%s", s);
if (s[] == 'M')
scanf("%d", &w);
else if (s[] == 'P')
--w;
else if (s[] == 'N')
++w;
else if (s[] == 'D'){
scanf("%d", &n);
splay.remove(w, n);
} else
if (s[] == 'G'){
scanf("%d", &n);
splay.print(w, n);
} else
if (s[] = 'I'){
scanf("%d", &n);
cur = ;
while (n--){
while(strI[cur] = getchar(), strI[cur] == '\n');
cur++;
}
splay.insert(w, cur);
}
}
return ;
}
BZOJ1507 [NOI2003]Editor的更多相关文章
- 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)
Description Input 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中可能会插入一些回车符,请忽略掉它 ...
- 【bzoj1507】[NOI2003]Editor /【bzoj1269】[AHOI2006]文本编辑器editor Splay
[bzoj1507][NOI2003]Editor 题目描述 输入 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中 ...
- 【BZOJ-1507】Editor 块状链表
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3397 Solved: 1360[Submit][Stat ...
- BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor
BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor 题意: 分析: splay模拟即可 注意1507的读入格式 ...
- 1507: [NOI2003]Editor(块状链表)
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4157 Solved: 1677[Submit][Stat ...
- 1507: [NOI2003]Editor
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MB Submit: 3535 Solved: 1435 [Submit][St ...
- [NOI2003]Editor & [AHOI2006]文本编辑器editor BZOJ1507&BZOJ1269
分析: Splay区间操作裸题,维护出区间信息,按照要求模拟,注意读入格式,并且考虑内存回收(开不下) 附上代码: #include <cstdio> #include <algor ...
- 【bzoj1507】[NOI2003]Editor
第二次写rope了 rope大法好!!! #include<algorithm> #include<iostream> #include<ext/rope> #in ...
随机推荐
- Android中的文件权限操作
默认本工程创建的文件本工程对其有读写权限. 我们可以通过context.openFileOutput("文件名", 模式): 我们可以创建私有, 共有, 只读, 只写文件, 默认的 ...
- 表单美化-原生javascript和jQuery多选按钮(兼容IE6)
前些天我们讲了下单选按钮的美化今天来做表单元素多选按钮的美化.我们的想法是:利用多选按钮是否被选中和是否不给选择的特性来为按钮的父元素添加对应的样式,就是说用什么的样式是由按钮的状态来决定. 用到的图 ...
- Linux_常用命令_04_挂载
1. mount [-t vfstype] [-o options] device dir ZC: -o 后面跟多个option的话,用逗号隔开.(例如:"mount -o rw,remou ...
- [转载] 使用异步 I/O 大大提高应用程序的性能
原文: http://www.ibm.com/developerworks/cn/linux/l-async/ Linux® 中最常用的输入/输出(I/O)模型是同步 I/O.在这个模型中,当请求发出 ...
- git各种撤销操作
撤销git add: git reset HEAD+路径 或者git reset --+路径 撤销commit: 1.回退到具体的嘻哈值 git reset --hard 2.回退后仍包含本地 ...
- 使用xml方式定义补间动画
在res下创建一个目录 anim目录 public class MainActivity extends Activity { private ImageView iv; @Override prot ...
- pl/sql developer执行光标所在行
一.发现问题 需要执行某一行语句时,需要选中该行语句,点击F8才行. 二.解决问题 中文版:工具->首选项->SQL窗口->自动选择语句 英文版:tools->preferen ...
- css-高度自适应的问题(body高度问题)
css-高度自适应的问题 对象height:100%并不能直接产生效果,是因为跟其父对象有关. #center{ height:100%; } 上面的css样式是无效的,不会产生任何效果. 需要改写: ...
- JSON和JSONP区别和联系
由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...
- css编码规范
css编码规范 https://segmentfault.com/a/1190000002460968 常用样式测试工具 W3C CSS validator:http://jigsaw.w3.org/ ...