二次联通门 : 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. Scala Map与Tuple

    创建Map // 创建一个不可变的Map val ages = Map("Leo" -> 30, "Jen" -> 25, "Jack&q ...

  2. Scratch编程:初识Scratch及编程工具安装(一)

    “ Scratch是一款由美国麻省理工学院(MIT)设计开发的少儿编程工具.” Scratch采用可视化.模块化的编程方式,非常适合青少年作为初次接触编程的工具和语言来学习,进而用其编写充满趣味的小程 ...

  3. Shiro身份认证、盐加密

    目的: Shiro认证 盐加密工具类 Shiro认证 1.导入pom依赖 <dependency> <groupId>org.apache.shiro</groupId& ...

  4. go开发 modules 的使用和代理

    go开发 modules 的使用和代理 初学go语言,一堆 来自谷歌的包如 import ( "code.google.com/xxx" ) 不翻墙是很难下载下来的. 另外还有麻烦 ...

  5. 监控SQL:通过SQL Server的DML触发器来监控哪些IP对表的数据进行了修改(2)

    原文:监控SQL:通过SQL Server的DML触发器来监控哪些IP对表的数据进行了修改(2) 在有些公司中,由于管理的不规范,或者是便于开发人员直接修改.部署程序,往往任何开发人员,都能登录到生产 ...

  6. 【转载】IIS网站配置不带www域名直接跳转带www的域名

    很多时候为了统一网站入口,需要将不带www的主域名解析到带www的域名记录下,当客户访问不带www的域名网址的时候自动跳转到带www的域名,在IIS Web服务器中可以通过URL重写模块来实现此功能, ...

  7. TR-TR模块资料汇总

    转载: TR模块培训 https://www.docin.com/p-1704805923.html 现金管理(Cash Management)和预算控制(Cash Budget Management ...

  8. Fortify漏洞之Cross-Site Scripting(XSS 跨站脚本攻击)

    书接上文,继续对Fortify漏洞进行总结,本篇主要针对XSS跨站脚步攻击漏洞进行总结,如下: 1.Cross-Site Scripting(XSS 跨站脚本攻击) 1.1.产生原因: 1. 数据通过 ...

  9. 【DRF框架】序列化组件

    DRF框架的序列化组件 在前后端分离的应用模式中,后端仅返回前端所需的数据,返回的数据类似是JSON,因此需要使用序列化组件进行序列化再将数据返回 使用JsonResponse做序列化 #  使用Js ...

  10. 用python批量插入数据到数据库中

    既然使用python操作数据库必不可少的得使用pymysql模块 可使用两种方式进行下载安装: 1.使用pip方式下载安装 pip install pymysql 2.IDE方式 安装完成后就可以正常 ...