是一道裸的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的更多相关文章

  1. BZOJ1507 [NOI2003]Editor 【splay】

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 4129  Solved: 1660 [Submit][St ...

  2. [BZOJ1507] [NOI2003] Editor (splay)

    Description Input 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中可能会插入一些回车符,请忽略掉它 ...

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

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

  4. 【BZOJ-1507】Editor 块状链表

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 3397  Solved: 1360[Submit][Stat ...

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

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

  6. 1507: [NOI2003]Editor(块状链表)

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 4157  Solved: 1677[Submit][Stat ...

  7. 1507: [NOI2003]Editor

    1507: [NOI2003]Editor Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 3535  Solved: 1435 [Submit][St ...

  8. [NOI2003]Editor & [AHOI2006]文本编辑器editor BZOJ1507&BZOJ1269

    分析: Splay区间操作裸题,维护出区间信息,按照要求模拟,注意读入格式,并且考虑内存回收(开不下) 附上代码: #include <cstdio> #include <algor ...

  9. 【bzoj1507】[NOI2003]Editor

    第二次写rope了 rope大法好!!! #include<algorithm> #include<iostream> #include<ext/rope> #in ...

随机推荐

  1. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. cdoj 851 方老师与素数 bfs

    方老师与素数 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit St ...

  3. 对称加密DES和TripleDES

    一.  对称加密 对称加密,是一种比较传统的加密方式,其加密运算.解密运算使用的是同样的密钥,信息的发送者和信息的接收者在进行信息的传输与处理时,必须共同持有该密码(称为对称密码).因此,通信双方都必 ...

  4. MongoDB 中遇到的一些错误

    1.在win平台上,使用ctrl+c关闭mongodb后,使用 mongod --dbpath=D:\mongodb\db --logpath=D:\mongodb\log.txt --port -- ...

  5. 个人博客Week3

    必应软件客户端测评 话不多说 先来一张高大上的客户端界面截图! 首先 映入眼帘的就是四个主要的模块!(1)词典(2)例句(3)翻译(4)应用 (1)词典: 在查询词条的时候,一旦查询了一个词条就不能够 ...

  6. struts2 if标签示例

    下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...

  7. web设计经验<二>设计华丽的用户体验的6个热门技巧

    你是否曾经下载了一个应用,却发现它“很难使用”?对于大多数智能手机用户来说,答案是肯定的. 有趣的是,每四个手机应用中就有一个应用在下载后被“打入冷宫”. 如果一个应用能够吸引一个人下载并且打开它,但 ...

  8. Linux下的字符集问题

    怎么设置Linux系统中文语言,这是很多小伙伴在开始使用Linux的时候,都会遇到一个问题,就是终端输入命令回显的时候中文显示乱码.出现这个情况一般是由于没有安装中文语言包,或者设置的默认语言有问题导 ...

  9. UML中类之间的几种关系

    类之间可能存在以下几种关系:关联(association).依赖(dependency).聚合(Aggregation,也有的称聚集).组合(Composition).泛化(generalizatio ...

  10. 免费在线客服QQ_网页接入及使用说明

    首先,注册一个QQ (haha,我觉得也是废话) 到QQ推广的网站设置,生成代码 链接:http://shang.qq.com/v3/widget.html 选择“免费开通”,然后就会看到下图,一般只 ...