好久没写splay了,写一发(写了一节课,调了一节课)

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#define mp make_pair
#define pa pair<int,int>
#define pb push_back
#define fi first
#define se second
#define Key Root->ch[1]->ch[0]
using namespace std;
inline void Get_Int(int &x)
{
x=; register char ch=getchar(); int f=;
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();} x*=f;
}
inline void Put_Int(int x)
{
char ch[]; register int top=;
if (x<) putchar('-'),x=-x;
if (x==) ch[++top]='';
while (x) ch[++top]=x%+'',x/=;
while (top) putchar(ch[top--]); putchar('\n');
}
inline int Max(int x,int y) {return x>y?x:y;}
inline int Max3(int x,int y,int z) {return Max(x,Max(y,z));}
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
inline bool StrCmp(char S1[],char S2[]) {for (int i=;i<;i++) if (S1[i]!=S2[i]) return false; return true;}
//=============================================
const int Maxn=;
const int Inf=0x3f3f3f3f;
int a[Maxn],pos,tot,c,n,m,Point;
char str[];
struct Node
{
int lx,rx,mx,sum,size,key,rev,same;
Node * pre,* ch[];
inline int d() {return this->pre->ch[]==this;}
inline void Setc(Node * r,int d) {r->pre=this; this->ch[d]=r;}
};
inline void Swap(Node *&x,Node *&y) {Node * T=x;x=y;y=T;}
Node Memory[Maxn],* port=Memory,* tmp[Maxn],* Bin[Maxn],* null=port++,* Root;
inline Node * NewNode(Node * f,int v)
{
Node * ret;
if (Point) ret=Bin[Point--]; else ret=port++;
ret->ch[]=ret->ch[]=null;
ret->size=,ret->pre=f;
ret->key=ret->lx=ret->rx=ret->mx=ret->sum=v;
ret->same=ret->rev=;
return ret;
}
inline void Get_Rev(Node * x)
{
if (x==null) return;
Swap(x->ch[],x->ch[]);
Swap(x->lx,x->rx);
x->rev^=;
}
inline void Get_Same(Node * x,int v)
{
if (x==null) return;
x->key=v;
x->sum=x->size*v;
x->lx=x->rx=x->mx=Max(v,x->size*v);
x->same=;
}
inline void Push_Up(Node * x)
{
if (x==null) return;
x->size=x->ch[]->size+x->ch[]->size+;
x->sum=x->ch[]->sum+x->ch[]->sum+x->key;
x->lx=Max(x->ch[]->lx,x->ch[]->sum+x->key+Max(x->ch[]->lx,));
x->rx=Max(x->ch[]->rx,x->ch[]->sum+x->key+Max(x->ch[]->rx,));
x->mx=Max3(x->ch[]->mx,x->ch[]->mx,Max(x->ch[]->rx,)+x->key+Max(x->ch[]->lx,));
}
inline void Push_Down(Node * x)
{
if (x==null) return;
if (x->rev)
{
Get_Rev(x->ch[]);
Get_Rev(x->ch[]);
x->rev=;
}
if (x->same)
{
Get_Same(x->ch[],x->key);
Get_Same(x->ch[],x->key);
x->same=;
}
}
Node * Build(int l,int r,Node * f)
{
if (l>r) return null;
int mid=(l+r)>>;
Node * ret=NewNode(f,a[mid]);
ret->ch[]=Build(l,mid-,ret);
ret->ch[]=Build(mid+,r,ret);
Push_Up(ret);
return ret;
}
inline void Init()
{
null->ch[]=null->ch[]=null->pre=null;
null->size=null->key=null->sum=null->same=null->rev=;
null->lx=null->rx=null->mx=-Inf;
Root=NewNode(null,-);
Root->ch[]=NewNode(Root,-);
for (int i=;i<=n;i++) Get_Int(a[i]);
Key=Build(,n,Root->ch[]);
Push_Up(Root->ch[]),Push_Up(Root);
}
//=========================================================
inline void Rotate(Node * x)
{
Node * y=x->pre; int d=x->d();
y->pre->Setc(x,y->d());
y->Setc(x->ch[!d],d);
x->Setc(y,!d);
Push_Up(y);
}
void Splay(Node * x,Node * Goal)
{
int s=; tmp[]=x; Node * r=x;
while (r->pre!=null) tmp[++s]=r=r->pre;
while (s) Push_Down(tmp[s--]);
while (x->pre!=Goal)
if (x->pre->pre==Goal) Rotate(x); else
(x->pre->d()==x->d())?(Rotate(x->pre),Rotate(x)):(Rotate(x),Rotate(x));
Push_Up(x);
if (Goal==null) Root=x;
}
//===========================================================
Node * Get_K(Node * x,int k)
{
Push_Down(x);
int t=x->ch[]->size+;
if (t==k) return x;
if (t>k) return Get_K(x->ch[],k);
else return Get_K(x->ch[],k-t);
}
inline void Handle(int pos,int tot)
{
Splay(Get_K(Root,pos),null);
Splay(Get_K(Root,pos+tot+),Root);
}
inline void Insert()
{
Get_Int(pos),Get_Int(n);
Handle(pos+,);
for (int i=;i<=n;i++) Get_Int(a[i]);
Key=Build(,n,Root->ch[]);
Push_Up(Root->ch[]),Push_Up(Root);
}
void Erase(Node * x)
{
if (x==null) return;
Erase(x->ch[]),Erase(x->ch[]);
Bin[++Point]=x;
}
inline void Delete()
{
Get_Int(pos),Get_Int(tot);
Handle(pos,tot);
Erase(Key); Key->pre=null; Key=null;
Push_Up(Root->ch[]),Push_Up(Root);
}
inline void Same()
{
Get_Int(pos),Get_Int(tot),Get_Int(c);
Handle(pos,tot);
Get_Same(Key,c);
Push_Up(Root->ch[]),Push_Up(Root);
}
inline void Rev()
{
Get_Int(pos),Get_Int(tot);
Handle(pos,tot);
Get_Rev(Key);
Push_Up(Root->ch[]),Push_Up(Root);
}
inline void Sum()
{
Get_Int(pos),Get_Int(tot);
Handle(pos,tot);
Put_Int(Key->sum);
}
inline void MaxSum()
{
Handle(,Root->size-);
Put_Int(Key->mx);
}
void InOrder(Node * x)
{
if (x==null) return;
Push_Down(x);
InOrder(x->ch[]);
printf("%d ",x->key);
InOrder(x->ch[]);
} int main()
{
Get_Int(n),Get_Int(m);
Init();
for (int i=;i<=m;i++)
{
scanf("%s",str);
if (StrCmp(str,"INSERT")) Insert();
if (StrCmp(str,"DELETE")) Delete();
if (StrCmp(str,"MAKE-SAME")) Same();
if (StrCmp(str,"REVERSE")) Rev();
if (StrCmp(str,"GET-SUM")) Sum();
if (StrCmp(str,"MAX-SUM")) MaxSum();
}
return ;
}

傻逼200+系列..

BZOJ 1500 Splay 全操作的更多相关文章

  1. BZOJ 1500 splay终结版...

    GSS系列有一丝丝像- 只不过那个是线段树 这个是splay 翻转 插入 删除啥的就是普通的splay 合在一起了而已 //By SiriusRen #include <cstdio> # ...

  2. [BZOJ 1500] [NOI2005] 维修数列

    题目链接:BZOJ - 1500 题目分析 我要先说一下,这道题我写了一晚上,然后Debug了一整个白天..........再一次被自己的蒟蒻程度震惊= = 这道题是传说中的Splay维护数列的Bos ...

  3. [BZOJ 1500] 维护序列

    Link: BZOJ 1500 传送门 Solution: 可能平衡树维护序列的所有操作都在这了吧…… 对序列的维护$fhq treap$和$Splay$都能做 有几个注意点: 1.维护序列时始终记得 ...

  4. C语言链表全操作(增,删,改,查,逆序,递增排序,递减排序,链式队列,链式栈)

    一,数据结构——链表全操作: 链表形式: 其中,每个节点(Node)是一个结构体,这个结构体包含数据域,指针域,数据域用来存放数据,指针域则用来指向下一个节点: 特别说明:对于单链表,每个节点(Nod ...

  5. BZOJ1500: [NOI2005]维修数列 [splay序列操作]【学习笔记】

    以前写过这道题了,但我把以前的内容删掉了,因为现在感觉没法看 重写! 题意: 维护一个数列,支持插入一段数,删除一段数,修改一段数,翻转一段数,查询区间和,区间最大子序列 splay序列操作裸题 需要 ...

  6. ROS tab键补全操作出现错误

    ros tab键补全操作出现错误如下: $ roslaunch sp[rospack] Warning: error while crawling /home/hemudu: boost::files ...

  7. 机器学习进阶-图像基本操作-边界补全操作 1.cv2.copyMakeBoder(img, top_size, bottom_size, left_size, right_size, cv2.BORDER_REPLICATE) 进行边界的补零操作 2.cv2.BORDER_REPLICATE(边界补零复制操作)...

    1.cv2.copyMakeBoder(img, top_size, bottom_size, left_size, right_size, cv2.BORDER_REPLICATE) 参数说明: i ...

  8. BZOJ.4034 [HAOI2015]树上操作 ( 点权树链剖分 线段树 )

    BZOJ.4034 [HAOI2015]树上操作 ( 点权树链剖分 线段树 ) 题意分析 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 ...

  9. P2596 [ZJOI2006]书架 && Splay 区间操作(三)

    P2596 [ZJOI2006]书架 题目描述 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书, ...

随机推荐

  1. Runnable和Thread的区别 (转)

    在java中可有两种方式实现多线程,一种是继承 Thread类,一种是实现Runnable接口:Thread类是在java.lang包中定义的.一个类只要继承了Thread类同时覆写了本类中的 run ...

  2. WebRequest使用

    // 待请求的地址 string url = "http://www.cnblogs.com"; // 创建 WebRequest 对象,WebRequest 是抽象类,定义了请求 ...

  3. mysql之常用操作

    1. 数据库介绍 什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据.我们也可以将数 ...

  4. c++11中的for简化用法

    1.序列for循环 map<string,int> m{{"a",1},{"b",2},{"c",3}} for(auto p: ...

  5. RCP:如何把Preferences中的项从一个类别移动到另一个类别

    前言 很久没写文章了,准备写一系列关于Eclipse RCP /Plugin的文章. 这些文章都是trouble shooting性质的,不准备写的很细,当你碰到这样的问题,google到时,能帮你把 ...

  6. URLClassLoader类

    URLClassLoader类 1.URLClassLoader类也是ClassLoader类的实现类,它的功能非常强大,他可以从本地文件系统中获取二进制文本来加载类,也可以从远程主机获取二进制文件来 ...

  7. WordPress搬家教程:换空间与换域名

    WordPress搬家教程:换空间与换域名 由于本人博客空间8月份已到期,便新购一个虚拟主机想进行WordPress搬家,于是特意在网上查了些WordPress搬家教程,进行了综合总结,并结合这次实操 ...

  8. 程序设计入门——C语言 第1周编程练习 1逆序的三位数(5分)

    第1周编程练习 查看帮助 返回   第1周编程练习题,直到课程结束之前随时可以来做.在自己的IDE或编辑器中完成作业后,将源代码的全部内容拷贝.粘贴到题目的代码区,就可以提交,然后可以查看在线编译和运 ...

  9. C#日常知识

    常量: 定义常量:const; 条件运算符: 表达式1?表达式2:表达式3[如果正确则执行表达式2,不正确执行表达式3] (例如:int result; result = 5>4?100:200 ...

  10. &与&&的区别

    &是“逻辑与”(“按位与”“位运算符”),一定要判断完所有的条件才能确定到底返回true还是false. &&是“短路与”(“逻辑运算符”),当从左至右判断时,一旦出现有一个条 ...