二次联通门 : luogu P3690 【模板】Link Cut Tree

莫名RE第8个点。。。。如果有dalao帮忙查错的话万分感激

#include <cstdio>
#include <iostream> #define Max 4000002 void read (int &now)
{
now = ;
bool temp = false;
register char word = getchar ();
while (word < '' || word > '')
{
if (word == '-')
temp = false;
word = getchar ();
}
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
if (temp)
now = -now;
} int N, M; struct S_D
{
S_D *child[]; S_D *father; int key;
int number; int Flandre;
S_D (int __x) : number (__x)
{
child[] = child[] = NULL; father = NULL;
key = __x;
Flandre = ;
} inline void Updata ()
{
/*
this->key ^= this->number;
if (this->child[0])
this->key ^= this->child[0]->key;
if (this->child[1])
this->key ^= this->child[1]->key;
*/
if (this->child[] != NULL && this->child[] != NULL)
this->key = this->child[]->key ^ this->child[]->key ^ this->number;
else if (this->child[] != NULL && this->child[] == NULL)
this->key = this->child[]->key ^ this->number;
else if (this->child[] != NULL && this->child[] == NULL)
this->key = this->child[]->key ^ this->number;
else
this->key = this->number;
//this->key = this->child[0]->key ^ this->number ^ this->child[1]->key;
return ;
} inline void Down ()
{
if (!this->Flandre)
return ;
std :: swap (this->child[], this->child[]);
if (this->child[])
this->child[]->Flandre ^= ;
if (this->child[])
this->child[]->Flandre ^= ;
this->Flandre = ;
} inline int Get_Pos ()
{
return this->father->child[] == this;
} inline int Is_Root ()
{
return !(this->father) || (this->father->child[] != this && this->father->child[] != this);
} }; S_D *data[Max];
S_D *node[Max]; class L_T
{ private : inline void Rotate (S_D *now)
{
int pos = now->Get_Pos () ^ ;
S_D *Father = now->father;
Father->child[pos ^ ] = now->child[pos];
if (now->child[pos])
now->child[pos]->father = Father;
now->father = Father->father;
if (!Father->Is_Root ())
now->father->child[Father->Get_Pos ()] = now;
Father->father = now;
now->child[pos] = Father;
Father->Updata ();
now->Updata ();
} inline void Splay (S_D *now)
{
int pos = ;
for (S_D *Father = now; ; Father = Father->father)
{
data[++pos] = Father;
if (Father->Is_Root ())
break;
}
for (; pos >= ; -- pos)
data[pos]->Down ();
for (; !now->Is_Root (); Rotate (now))
if (!now->father->Is_Root ())
Rotate (now->Get_Pos () == now->father->Get_Pos () ? now->father : now);
now->Updata ();
} inline void Access (S_D *now)
{
for (S_D *Pre = NULL; now; Pre = now, now = now->father)
{
Splay (now);
now->child[] = Pre;
now->Updata ();
}
} inline void Make_Root (S_D *now)
{
Access (now);
Splay (now);
now->Flandre ^= ;
} public : inline void Cut (S_D *x, S_D *y)
{
Make_Root (x);
Access (y);
Splay (y);
x->father = y->child[] = NULL;
y->Updata ();
} inline void Link (S_D *x, S_D *y)
{
Make_Root (x);
x->father = y;
} inline void Split (S_D *x, S_D *y)
{
Make_Root (x);
Access (y);
Splay (y);
} inline bool Find (S_D *x, S_D *y)
{
while (x->child[])
x = x->child[];
while (y->child[])
y = y->child[];
return x == y;
} inline int Query (int x, int y)
{
Split (node[x], node[y]);
return node[y]->key;
} inline void Change (int x, int y)
{
Access (node[x]);
Splay (node[x]);
node[x]->number = y;
node[x]->Updata ();
}
}; L_T Make; int main (int argc, char *argv[])
{
read (N);
read (M);
for (register int i = , x; i < N; i ++)
{
read (x);
node[i] = new S_D (x);
}
int x, y, type;
for (; M --; )
{
read (type);
read (x);
read (y);
if (type == )
printf ("%d\n", Make.Query (-- x, -- y));
else if (type == )
{
x --;
y --;
if (!Make.Find (node[x], node[y]))
Make.Link (node[x], node[y]);
}
else if (type == )
{
x --;
y --;
if (Make.Find (node[x], node[y]))
Make.Cut (node[x], node[y]);
}
else
Make.Change (-- x, y);
}
return ;
}

(RE) luogu P3690 【模板】Link Cut Tree的更多相关文章

  1. 洛谷P3690 [模板] Link Cut Tree [LCT]

    题目传送门 Link Cut Tree 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代 ...

  2. LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)

    为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...

  3. 模板Link Cut Tree (动态树)

    题目描述 给定N个点以及每个点的权值,要你处理接下来的M个操作.操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联 ...

  4. 洛谷.3690.[模板]Link Cut Tree(动态树)

    题目链接 LCT(良心总结) #include <cstdio> #include <cctype> #include <algorithm> #define gc ...

  5. 【刷题】洛谷 P3690 【模板】Link Cut Tree (动态树)

    题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...

  6. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...

  7. AC日记——【模板】Link Cut Tree 洛谷 P3690

    [模板]Link Cut Tree 思路: LCT模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 30 ...

  8. 洛谷P3690 Link Cut Tree (模板)

    Link Cut Tree 刚开始写了个指针版..调了一天然后放弃了.. 最后还是学了黄学长的板子!! #include <bits/stdc++.h> #define INF 0x3f3 ...

  9. Luogu 3690 Link Cut Tree

    Luogu 3690 Link Cut Tree \(LCT\) 模板题.可以参考讲解和这份码风(个人认为)良好的代码. 注意用 \(set\) 来维护实际图中两点是否有直接连边,否则无脑 \(Lin ...

随机推荐

  1. 『Python基础练习题』day05

    # 请将列表中的每个元素通过 "_" 链接起来. users = ['毛利兰', '柯南', '怪盗基德'] # 请将元组 v1 = (11, 22, 33) 中的所有元素追加到列 ...

  2. 自己用ansible加shell 写的自动安装kubernetes的脚本

    脚本地址:https://github.com/shatianxiaozi/auto_install_k8s.git 1. 下载 git clone https://github.com/shatia ...

  3. vue的交互

    交互     Vue做交互需要引入一个库:vue-resouce.js     get:      post     jsonp   <script src="vue.js" ...

  4. VBA数组(十四)

    我们都知道,一个变量是一个存储值的容器. 有时,开发人员希望一次可以在一个变量中保存多个值. 当一系列值存储在单个变量中时,则称为数组变量. 数组声明 数组声明的方式与声明变量相同,只是数组变量的声明 ...

  5. css 设置overflow:scroll 滚动条的样式

    /* 定义滚动条样式 */ ::-webkit-scrollbar { width: 6px; height: 6px; background-color: rgba(240, 240, 240, 1 ...

  6. pycharm git 用法总结

    一.配置git 二.登录GitHub账号 三.创建git respository 四.提交文件 五.共享给GitHub 六.修改文件push到版本库 七.从版本库checkout 项目

  7. FreeRTOS 任务创建和删除(动态)

    TaskHandle_t taskhandle; TaskHandle_t taskhandle1; void vTask(void *t) { int i = 0; while(1) { i++; ...

  8. arm9交叉编译工具链

    Arm-linux-gcc: gcc和arm-linux-gcc的头文件并不一样. Eg. Arm-linux-ld:链接器,-T参数是使用链接器脚本. Eg. Arm-linux-readelf:读 ...

  9. GitHub开源的10个超棒后台管理面板

    目录1.AdminLTE 2.vue-Element-Admin 3.tabler 4.Gentelella 5.ng2-admin 6.ant-design-pro 7.blur-admin 8.i ...

  10. 网上的JAVA语言的某个测试框架

    https://github.com/wenchengyao/testLJTT.git 使用maven打包,mvn clean install 在运行的时候,java -jar testLJTT.ja ...