(RE) luogu P3690 【模板】Link Cut Tree
二次联通门 : 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的更多相关文章
- 洛谷P3690 [模板] Link Cut Tree [LCT]
题目传送门 Link Cut Tree 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代 ...
- LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)
为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...
- 模板Link Cut Tree (动态树)
题目描述 给定N个点以及每个点的权值,要你处理接下来的M个操作.操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联 ...
- 洛谷.3690.[模板]Link Cut Tree(动态树)
题目链接 LCT(良心总结) #include <cstdio> #include <cctype> #include <algorithm> #define gc ...
- 【刷题】洛谷 P3690 【模板】Link Cut Tree (动态树)
题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...
- P3690 【模板】Link Cut Tree (动态树)
P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...
- AC日记——【模板】Link Cut Tree 洛谷 P3690
[模板]Link Cut Tree 思路: LCT模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 30 ...
- 洛谷P3690 Link Cut Tree (模板)
Link Cut Tree 刚开始写了个指针版..调了一天然后放弃了.. 最后还是学了黄学长的板子!! #include <bits/stdc++.h> #define INF 0x3f3 ...
- Luogu 3690 Link Cut Tree
Luogu 3690 Link Cut Tree \(LCT\) 模板题.可以参考讲解和这份码风(个人认为)良好的代码. 注意用 \(set\) 来维护实际图中两点是否有直接连边,否则无脑 \(Lin ...
随机推荐
- Arm-Linux 移植 alsa
ref : https://www.cnblogs.com/yutingliuyl/p/6718875.html https://blog.csdn.net/yuanxinfei920/article ...
- Jira是什么
JIRA这个工具接触有好几年了,在多个海外项目上都用过这个工具.去年又在项目上深度使用后就有点爱不释手了,回国后也在找机会推荐给其它项目上用.最近正好有新项目需要用,借这个机会把JIRA的配置学习的过 ...
- Vue $emit $event 传值(子to父)
事件名 始终使用 kebab-case 的事件名. 通过事件向父组件发送信息 子组件中EnFontsize.vue中$emit <button @click="$emit('enlar ...
- js按钮频繁提交解决方案:
1.封装js: /// 函数节流 xhz.canRun = true; xhz.Throttling = function () { if (!xhz.canRun) { layer.msg('处理中 ...
- 【转载】Session对象的作用以及常见属性
Session对象是Asp.Net应用程序中非常重要的一个内置对象,Session是指用户从打开浏览器访问服务器到关闭浏览器之间的会话状态,在一个会话期间,服务器会自动分配一个标识SessionId. ...
- win10如何安装mariadb
一.下载.安装 1.下载mariadb(https://downloads.mariadb.org/),解压 2.进入bin目录下执行(管理员模型-powershell) .\mysqld.exe - ...
- JavaScript作用域、作用域链 学习随笔
(本文是这些知识点的自我理解.写之余从头回顾,加深理解.取得更多收获之用.) 作用域(scope) 程序设计概念,通常来说,一段程序代码中所用到的名字(JS叫标识符(如变量名.函数名.属性名.参数.. ...
- 【前端适配】vw单位移动端适配方案
近些年移动端的强势崛起,导致移动端适配越来越重要,个人之前一直使用的是rem进行适配,但是发现并不是非常完美,给力的是大漠老师写了一篇<如何在Vue项目中使用vw实现移动端适配>,比较完美 ...
- python与mysql的数据交互
一 Python 中操作 MySQL 步骤 1.1 安装pymysql命令 sudo pip3 install pymysql 安装软件:sudo apt-get install 软件名称 安装模块: ...
- imx6q 启动logo
转:https://wenku.baidu.com/view/81fa0f3982c4bb4cf7ec4afe04a1b0717fd5b30e.html?rec_flag=default&sx ...