#include <cstdio>
const int Maxn=;
inline void Get_Int(int & x)
{
char ch=getchar(); x=;
while (ch<'' || ch>'') ch=getchar();
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
}
//========================================
char str[];
int n,m,u,v;
struct Node;
inline void Swap(Node *&x,Node *&y);
struct Node
{
Node * pre,* ch[];
int rev;
inline int d() {return pre->ch[]==this;}
inline void Rev() {Swap(ch[],ch[]),rev^=;}
inline void setc(Node * r,int d) {ch[d]=r; r->pre=this;}
};
Node Memory[Maxn],* Port=Memory,* null,* S[Maxn],* t[Maxn];
inline void Swap(Node *&x,Node *&y) {Node * t=x;x=y;y=t;}
inline void Init() {null=Port++; null->rev=; null->pre=null->ch[]=null->ch[]=null;}
inline Node * NewNode(){Node * Ret=Port++; Ret->rev=; Ret->pre=Ret->ch[]=Ret->ch[]=null; return Ret;}
inline bool IsRoot(Node * x) {return x->pre==null || (x->pre->ch[]!=x && x->pre->ch[]!=x);}
inline bool Push_Down(Node * x)
{
if (x->rev)
{
x->rev=;
x->ch[]->Rev();
x->ch[]->Rev();
}
}
inline void Rotate(Node * x)
{
Node * y=x->pre; int d=x->d();
Push_Down(y); Push_Down(x);
if (IsRoot(y)) x->pre=y->pre; else y->pre->setc(x,y->d());
y->setc(x->ch[!d],d);
x->setc(y,!d);
}
inline void Splay(Node * x)
{
Push_Down(x);
while (!IsRoot(x))
if (IsRoot(x->pre)) Rotate(x); else
(x->pre->d()==x->d()) ? (Rotate(x->pre),Rotate(x)) : (Rotate(x),Rotate(x));
}
inline void Access(Node * f)
{
Node * c=null;
while (f!=null)
{
Splay(f);
f->ch[]=c;
c=f;
f=f->pre;
}
}
inline void Make_Root(Node * x)
{
Access(x),Splay(x),x->Rev();
}
inline void Link(Node * x,Node * y)
{
Make_Root(x),x->pre=y;
}
inline void Cut(Node * x,Node * y)
{
Access(x),Splay(x),Splay(y);
if (y->pre!=x) Swap(x,y);
Access(x),Splay(x),Splay(y);
y->pre=null;
}
inline Node * Find(Node * x)
{
while (x->pre!=null) x=x->pre; return x;
}
inline bool Check(Node * x,Node * y)
{
if (Find(x)==Find(y)) return true; else return false;
}
int main()
{
Init();
Get_Int(n),Get_Int(m);
for (int i=;i<=n;i++) t[i]=NewNode();
for (int i=;i<=m;i++)
{
scanf("%s",str); Get_Int(u),Get_Int(v);
if (str[]=='C') Link(t[u],t[v]);
if (str[]=='D') Cut(t[u],t[v]);
if (str[]=='Q') puts(Check(t[u],t[v])?"Yes":"No");
}
return ;
}

BZOJ 2409

 #include <cstdio>
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 Min(int x,int y) {return x>y?y:x;}
//===============================================
const int Maxn=;
int n,m,k[Maxn],x,y,Type;
struct Node
{
Node * pre,* ch[];
int size,rev;
inline int d() {return pre->ch[]==this;}
inline void setc(Node * r,int d) {ch[d]=r; r->pre=this;}
};
Node Memory[Maxn],* port=Memory,* t[Maxn],* null,* S[Maxn];
inline void Swap(Node *&x,Node *&y) {Node * t=x;x=y;y=t;}
inline void Init() {null=port++; null->rev=; null->size=;null->pre=null->ch[]=null->ch[]=null;}
inline Node * NewNode(){Node * Ret=port++; Ret->ch[]=Ret->ch[]=Ret->pre=null;Ret->size=;Ret->rev=; return Ret;}
inline void Push_Up(Node * x) {x->size=x->ch[]->size+x->ch[]->size+;}
inline void Push_Down(Node * x)
{
if (x->rev)
{
x->ch[]->rev^=;
x->ch[]->rev^=;
x->rev=;
Swap(x->ch[],x->ch[]);
}
}
inline bool IsRoot(Node * x) {return x->pre==null || (x->pre->ch[]!=x && x->pre->ch[]!=x);} inline void Rotate(Node * x)
{
Node * y=x->pre; int d=x->d();
if (IsRoot(y)) x->pre=y->pre; else y->pre->setc(x,y->d());
y->setc(x->ch[!d],d);
x->setc(y,!d);
Push_Up(y),Push_Up(x);
}
inline void Splay(Node * x)
{
int s=; S[]=x; Node * r=x;
while (!IsRoot(r->pre)) S[++s]=r=r->pre;
while (s) Push_Down(S[s--]); while (!IsRoot(x))
if (IsRoot(x->pre)) Rotate(x); else
(x->pre->d()==x->d()) ? (Rotate(x->pre),Rotate(x)) : (Rotate(x),Rotate(x));
Push_Up(x);
} inline void Access(Node * f)
{
Node * c=null;
while (f!=null)
{
Splay(f);
f->ch[]=c;
c=f;
f=f->pre;
}
}
inline void Make_Root(Node * r)
{
Access(r),Splay(r),r->rev^=;
}
inline void Link(Node * x,Node * y)
{
Make_Root(x);x->pre=y;
}
inline void Cut(Node * x,Node * y)
{
Access(x),Splay(y);
if (y->pre!=x) Swap(x,y);
Access(x),Splay(y);
y->pre=null;
}
int main()
{
// freopen("c.in","r",stdin);
Init();
Get_Int(n);
for (int i=;i<=n+;i++) t[i]=NewNode();
for (int i=;i<=n;i++)
Get_Int(x),k[i]=Min(i+x,n+),Link(t[i],t[k[i]]);
Get_Int(m); Make_Root(t[n+]);
for (int i=;i<=m;i++)
{
Get_Int(Type);
if (Type==)
{
Get_Int(x); x++;
Make_Root(t[n+]);
Access(t[x]),Splay(t[x]);
Put_Int(t[x]->size-);
}
if (Type==)
{
Get_Int(x),Get_Int(y); x++;
Cut(t[x],t[k[x]]);
k[x]=Min(n+,x+y);
Link(t[x],t[k[x]]);
}
}
return ;
}

BZOJ 2002

调了好久,明天在做几题。

8.17

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
inline void Get_Int(int &x)
{
x=; char ch=getchar();
while (ch<'' || ch>'') ch=getchar();
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
}
inline int Max(int x,int y) {return x>y?x:y;}
inline int Min(int x,int y) {return x>y?y:x;}
//===========================================
const int Maxn=;
struct Node
{
Node * pre,* ch[]; int Rev,Key,v;
inline int d() {return pre->ch[]==this;}
inline void setc(Node * x,int d) {ch[d]=x; x->pre=this;}
};
Node Memory[Maxn<<],* port=Memory,* null,* Nd[Maxn];
int u,v,n,m,x,Type;
inline bool IsRoot(Node * x) {return x->pre==null || (x->pre->ch[]!=x && x->pre->ch[]!=x);}
inline void Swap(Node *&x,Node *&y) {Node * T=x;x=y;y=T;}
inline Node * NewNode(int v) {Node * Ret=port++; Ret->v=Ret->Key=v; Ret->Rev=; Ret->pre=Ret->ch[]=Ret->ch[]=null; return Ret;}
inline void Init() {null=port++; null->pre=null->ch[]=null->ch[]=null; null->Rev=null->Key=null->v=;}
inline void Get_Rev(Node * x)
{
if (x==null) return;
x->Rev^=; Swap(x->ch[],x->ch[]);
}
inline void Push_Down(Node * x)
{
if (x->Rev)
{
x->Rev=;
Get_Rev(x->ch[]);
Get_Rev(x->ch[]);
}
}
inline void Push_Up(Node * x)
{
x->v=x->ch[]->v^x->ch[]->v^x->Key;
}
inline void Rotate(Node * x)
{
Node * y=x->pre; int d=x->d();
Push_Down(y),Push_Down(x);
if (IsRoot(y)) x->pre=y->pre; else y->pre->setc(x,y->d());
y->setc(x->ch[!d],d);
x->setc(y,!d);
Push_Up(y),Push_Up(x);
}
inline void Splay(Node * x)
{
Push_Down(x);
while (!IsRoot(x))
if (IsRoot(x->pre)) Rotate(x); else
(x->d()==x->pre->d())?(Rotate(x->pre),Rotate(x)):(Rotate(x),Rotate(x));
Push_Up(x);
}
inline void Access(Node * f)
{
Node * x=null;
while (f!=null)
{
Splay(f);
f->ch[]=x;
x=f;
f=f->pre;
}
}
inline void Make_Root(Node * x)
{
Access(x); Splay(x); Get_Rev(x);
}
inline void Link(Node * x,Node * y)
{
Make_Root(x),x->pre=y;
}
inline void Cut(Node * x,Node * y)
{
Access(x),Splay(x),Splay(y);
if (y->pre!=x) Swap(x,y);
Access(x),Splay(x),Splay(y);
y->pre=null;
}
inline Node * Find(Node * x)
{
while (x->pre!=null) x=x->pre; return x;
}
inline bool Check(int p,int q)
{
if (Find(Nd[p])==Find(Nd[q])) return true; return false;
}
//==================================
inline void Query()
{
Get_Int(u),Get_Int(v);
Make_Root(Nd[u]),Access(Nd[v]),Splay(Nd[v]);
printf("%d\n",Nd[v]->v);
}
inline void Connect()
{
Get_Int(u),Get_Int(v);
if (Check(u,v)) return;
Link(Nd[u],Nd[v]);
}
inline void Delete()
{
Get_Int(u),Get_Int(v);
if (!Check(u,v)) return;
Cut(Nd[u],Nd[v]);
}
inline void Modify()
{
Get_Int(u),Get_Int(v);
Make_Root(Nd[u]); Nd[u]->Key=v; Push_Up(Nd[u]);
}
int main()
{
Get_Int(n),Get_Int(m); Init();
for (int i=;i<=n;i++) Get_Int(x),Nd[i]=NewNode(x);
for (int i=;i<=m;i++)
{
Get_Int(Type);
if (Type==) Query();
if (Type==) Connect();
if (Type==) Delete();
if (Type==) Modify();
}
return ;
}

BZOJ 3282

BZOJ 2002 && BZOJ 2409 LCT && BZOJ 3282 初步练习的更多相关文章

  1. 以 BZOJ 2002 为例学习有根树LCT(Link-Cut Tree)

    以BZOJ 2002 弹飞绵羊为例学习有根树LCT(Link-Cut Tree) 注:本文非常简单,只涉及有根树LCT,对于无根树,LCT还有几个本文没有提到的操作,以后慢慢更新 =v= 知识储备 [ ...

  2. lct 模版题 bzoj 2002 2049

    很早就有人给我推荐的模版题,然后我最近才刷的(' '    ) 昨天的tree 不知道比他们高到哪里去了,我和他谈笑风生啊! bzoj 2002 弹飞绵羊 重点:这道题的cut和link 由于这道题链 ...

  3. bzoj 2002 Bounce 弹飞绵羊

    bzoj 2002 Bounce 弹飞绵羊 设一个虚拟节点表示被弹飞,则每个点的后继点是唯一确定的,每个点向它的后继点连边,就形成了一颗树. 询问就是问某个节点到虚拟节点的路径长度,修改就删除原来向后 ...

  4. [BZOJ - 2631] tree 【LCT】

    题目链接:BZOJ - 2631 题目分析 LCT,像线段树区间乘,区间加那样打标记. 这道题我调了一下午. 提交之后TLE了,我一直以为是写错了导致了死循环. 于是一直在排查错误.直到.. 直到我看 ...

  5. [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree)

    [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree) 题面 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一 ...

  6. ●BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题解: LCT 如果把弹跳的起点和终点连一条边,弹出去的与n+1号点连边, 则不难发现 ...

  7. Kruskal算法及其类似原理的应用——【BZOJ 3654】tree&&【BZOJ 3624】[Apio2008]免费道路

    首先让我们来介绍Krukal算法,他是一种用来求解最小生成树问题的算法,首先把边按边权排序,然后贪心得从最小开始往大里取,只要那个边的两端点暂时还没有在一个联通块里,我们就把他相连,只要这个图里存在最 ...

  8. bzoj 2002 [Hnoi2010]Bounce 弹飞绵羊(LCT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2002 [题意] 给定n个数的序列,i可以跳到i+k[i],需要能够修改k并可以查询跳出 ...

  9. bzoj 2002 : [Hnoi2010]Bounce 弹飞绵羊 (LCT)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 题面: 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: ...

随机推荐

  1. KMS安装后激活机器

    slmgr /skms 192.168.26.82 slmgr /ato

  2. 使用SecureCRT远程链接Ubuntu出现 Change of username or service not allowed的问题

    RT:    首先是确认ubuntu上有运行 sshd服务的 但是用SecureCRT链接时报错,默认用户名是root: 打开ssh_config检查下是否禁止直接用root登陆 这句 改成yes o ...

  3. ios基础篇(二十八)—— UITableView的上拉加载

    本文主要展示一个demo实现UITableView的上拉加载数据: 先看看效果图: 接着上拉,加载更多数据: 主要实现的效果是在我们上拉结束拖拽之后,开始加载数据,数据加载的过程中有滚动轮提示用户正在 ...

  4. java selenium (二) 环境搭建方法一

    webdriver 就是selenium 2.    webdriver 是一款优秀的,开源的,自动化测试框架. 支持很多语言.  本文描述的是用java Eclipse 如何搭建环境 阅读目录   ...

  5. java selenium (三) 环境搭建 基于Maven

    现在Java的大部分项目都是基于Maven,  在Maven项目中使用Selenium2. 非常简单. 首先你需要配置好Maven的环境 可以参考本博客的Maven教程系列,Maven入门教程(一) ...

  6. Spring Framework的核心:IOC容器的实现

    2.1   Spring IoC容器概述 2.1.1 IoC容器和依赖反转模式 依赖反转的要义,如果合作对象的引用或依赖关系的管理由具体对象来完成,会导致代码的高度耦合和可测性的降低.依赖控制反转的实 ...

  7. 山锅(samgor)的博客 2014

    搞移动端的前端开发已经3年,悄悄地从一个前端小白变成老油条. 项目已经做了好几个,最近发现技术的提升貌似停滞不前.说很菜吧,知道的还是不少.说精通吧,自我感觉还算不上. 认真的考虑下这个问题,觉得技术 ...

  8. IIS7 404 模块 IIS Web Core 通知 MapRequestHandler 处理程序 StaticFile 错误代码 0x80070002

    <system.webServer> <!--添加--> <modules runAllManagedModulesForAllRequests="true&q ...

  9. 移动互联网公司如何将BPM流程管理变身移动化?

    背景介绍 OPPO是广东欧珀移动通信有限公司的旗下品牌,成立于2004年,是一家全球性的智能终端和移动互联网公司,致力于为客户提供最先进和最精致的智能手机.高端影音设备和移动互联网产品与服务,业务覆盖 ...

  10. Websocket 协议解析

    WebSocket protocol 是HTML5一种新的协议.它是实现了浏览器与服务器全双工通信(full-duplex).          现 很多网站为了实现即时通讯,所用的技术都是轮询(po ...