好久没写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. IOS new Date() 时间转换失败问题以及其他问题

    一: ios下必须标准格式用'/'分割格式 转换没问题:  new Date('2016/5/30 12:15:20') 二:ie9兼容模式以及以下ie版本 console用前需判断 if(windo ...

  2. IntelliJ IDEA 14和Maven创建java web项目

    安装Maven 下载安装 去maven官网下载最新版. 解压到安装目录. 配置 右键桌面的计算机图标,属性–>高级系统设置–>环境变量,添加M2_HOME的环境变量,然后将该变量加入的PA ...

  3. Linux命令帮助中尖括号<>和方括号[]以及省略号...的含义

    在方括号内的表达式("[" 和 "]"之间的字符)是可选的(写命令时要去掉括号). 在尖括号内的表达式("[" 和 "]" ...

  4. 针对高通BMS的研究 高通电量计

    点击打开链接 高通8064 8974 8926等pm芯片都集成了电量计,估计后续芯片都会一直存在,现在许多项目UI状态栏电池都有百分比显示,所以需要深入分析BMS有助于解决电量方面的BUG. 一: S ...

  5. win安装NLTK出现的问题

    一.今天学习Python自然语言处理(NLP processing) 需要安装自然语言工具包NLTK Natural Language Toolkit 按照教程在官网https://pypi.pyth ...

  6. JAVA 使用POI导出数据格式为Execl

    需要下载一个poi的jar包. 控制器 @Override public void getContractListExecl(Contract contract, BindingResult resu ...

  7. 用OPencv配置vs2010

    第一次作业,图像的识别存储和显示 此次选用的是Microsoft Visual Studio 2010软件,在配置和opencv的时候,要选好版本苟泽造成不兼容,因此我选用的为opencv 2.4.1 ...

  8. Python 去剑式

    Python 去剑式 种种变化,用以体演总诀.共有三百六十种变化. 用以破解普天下各门各派的剑法.「破剑式」虽只一式,但其中于天下各门各派剑法要义兼收并蓄:虽说「无招」却是以普天下剑法之招数为根基,因 ...

  9. absolute和fixed

    共同点: 改变行内元素的呈现方式,display设置为block:让元素脱离文档流,不占据空间:默认会覆盖到非定位元素上. 不同点: absolute的根元素是相对于static定位以外的第一个父元素 ...

  10. 如何搭建一个linux服务器

    1, 首先 下载一个linux server 系统镜像 ubuntu 64bit下载 http://www.ubuntu.com/download/server/thank-you/?version= ...