是一道裸的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. 3.25考试(hnoi难度)----神奇的一日游

    T1怕老婆 有一天hzy9819,来到了一座大城市拥有了属于他自己的一双滑板鞋.但是他还是不满足想要拥有属于自己的一栋楼,他来到了一条宽敞的大道上,一个一个记录着这些楼的层数以方便自己选择. hzy9 ...

  2. 关于Docker 常用命令

    Docker 常用命令 分类列一下常用的CLI命令 仓库相关 search/ pull / push / login etc. 例:docker pull ubuntu 从仓库下载ubuntuimag ...

  3. Java Abstract class and Interface

    Abstract Class 在定义class的时候必须有abstract 关键字 抽象方法必须有abstract关键字. 可以有已经实现的方法. 可以定义static final 的常量. 可以实现 ...

  4. ABAP 没有地方输入\H 进入DEBUG 怎么办?

    把如下代码保存,命名debug.txt  ,把这个文件拖拉到要调试的窗口. [FUNCTION]Command=/HTitle=Barry TestType=SystemCommand

  5. AFNetworking请求中含有中文时程序崩溃

    出现error: Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error ...

  6. [玲珑OJ1044] Quailty and Binary Operation (FFT+cdq分治)

    题目链接 题意:给定两个长度为n的数组a与长度为m的数组b, 给定一个操作符op满足 x op y = x < y ? x+y : x-y.  有q个询问,每次给出询问c,问:有多少对(i, j ...

  7. 学习日记day8:移动端页面流程优化

    一:切图 1:切那些(移动端能不用图片就不用图片:logo单独切因为要带链接) 2:普通切(快捷键:复制到新图层  选中 复制 新建 粘贴 保存)  3:类似切 (选中多个图层  矩形框多选  选择工 ...

  8. sscanf的用法(转)

    队长做上海邀请赛的I题时遇到一个棘手的问题,字符串的处理很麻烦,按传统的gets全部读入的话还要做N多处理,太浪费时间. 回来之后搜了一下sscanf的用法发现可以很好的解决这一类问题,各种百度,转来 ...

  9. CentOS6.x最下化安装及优化配置

    一.最小化安装自定义额外包组 1.1 选择最小化安装 1.2 自定义额外的包组 Base System的选择 Development的选择 如果需要中文的支持可以在Languages中勾选中文 1.3 ...

  10. Hibernate Projections(投影、统计、不重复结果)

    Hibernate除了处理查询结果集中的对象之外,还可以将结果集中的结果当做行和列集来使用,这与通过JDBC执行select查询获得的数据的使用方式相似.因此,Hibernate也支持属性.统计函数和 ...