二次联通门 : 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. chrome下载离线安装包

    chrome下载离线安装包 - codeflyto - 博客园 下载页面:

  2. python读取文件行数和某行内容

    学习记录: python计算文件的行数和读取某一行内容的实现方法 - nkwy2012 - 博客园https://www.cnblogs.com/nkwy2012/p/6023710.html 文本文 ...

  3. protobuf的使用(netty传输多种对象类型)

    重点是: 1.枚举DataType的定义 2.oneof的使用

  4. Spring Cloud Alibaba学习笔记(5) - 整合Sentinel及Sentinel规则

    整合Sentinel 应用整合Sentinel 在dependencies中添加依赖,即可整合Sentinel <dependency> <groupId>com.alibab ...

  5. 常用算法之排序(Java)

    一.常用算法(Java实现) 1.选择排序(初级算法) 原理:有N个数据则外循环就遍历N次并进行N次交换.内循环实现将外循环当前的索引i元素与索引大于i的所有元素进行比较找到最小元素索引,然后外循环进 ...

  6. Linux判断SSD或HDD + 模拟SSD

    判断方法 方法一 判断cat /sys/block/*/queue/rotational的返回值(其中*为你的硬盘设备名称,例如sda等等),如果返回1则表示磁盘可旋转(HDD),返回0,则表示磁盘不 ...

  7. typeAliasesPackage 属性的作用

    applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...

  8. Java定时任务工具详解之Timer篇

    Java定时任务调度工具详解 什么是定时任务调度? ◆ 基于给定的时间点,给定的时间间隔或者给定的执行次数自动执行的任务. 在Java中的定时调度工具? ◆ Timer       ◆Quartz T ...

  9. 【转载】Sqlserver存储过程中使用Select和Set给变量赋值

    Sqlserver存储过程是时常使用到的一个数据库对象,在存储过程中会使用到Declare来定义存储过程变量,定义的存储过程变量可以通过Set或者Select等关键字方法来进行赋值操作,使用Set对存 ...

  10. css 垂直方向 margin 边距 重合

    1:控制两个相邻边盒子之间的距离,在A或者B盒子上用margin控制,就可以控制距离了. 2:父子级之间的元素,常规文档流中,只要垂直外边距直接接触就会发生合并.比如在写header标签时,想移动he ...