3282. Tree【LCT】
Description
Input
Output
对于每一个0号操作,你须输出X到Y的路径上点权的Xor和。
Sample Input
1
2
3
1 1 2
0 1 2
0 1 1
Sample Output
1
#include<iostream>
#include<cstring>
#include<cstdio>
#define N (300000+100)
using namespace std;
int Father[N],Son[N][],Rev[N],Val[N],Xor[N];
int n,m; void Update(int x){Xor[x]=Val[x]^Xor[Son[x][]]^Xor[Son[x][]];}
int Get(int x) {return Son[Father[x]][]==x;}
int Is_root(int x) {return Son[Father[x]][]!=x && Son[Father[x]][]!=x;} void Rotate(int x)
{
int wh=Get(x);
int fa=Father[x],fafa=Father[fa];
if (!Is_root(fa)) Son[fafa][Son[fafa][]==fa]=x;
Father[fa]=x;
Son[fa][wh]=Son[x][wh^];
if (Son[fa][wh]) Father[Son[fa][wh]]=fa;
Father[x]=fafa;
Son[x][wh^]=fa;
Update(fa);
Update(x);
} void Pushdown(int x)
{
if (Rev[x] && x)
{
if (Son[x][]) Rev[Son[x][]]^=;
if (Son[x][]) Rev[Son[x][]]^=;
swap(Son[x][],Son[x][]);
Rev[x]=;
}
} int Push(int x)
{
if (!Is_root(x)) Push(Father[x]);
Pushdown(x);
} void Splay(int x)
{
Push(x);
for (int fa; !Is_root(x); Rotate(x))
if (!Is_root(fa=Father[x]))
Rotate(Get(fa)==Get(x)?fa:x);
} void Access(int x) {for (int y=;x;y=x,x=Father[x]) Splay(x),Son[x][]=y,Update(x);}
int Find_root(int x) {Access(x); Splay(x); while (Son[x][]) x=Son[x][]; return x;}
void Make_root(int x) {Access(x); Splay(x); Rev[x]^=;}
void Link(int x,int y) {Make_root(x); Father[x]=y;}
void Cut(int x,int y) {Make_root(x); Access(y); Splay(y); Son[y][]=Father[x]=;}
void Query(int x,int y){Make_root(x);Access(y); Splay(y); printf("%d\n",Xor[y]);} int main()
{
int opt,x,y;
scanf("%d%d",&n,&m);
for (int i=; i<=n; ++i)
scanf("%d",&Val[i]),Xor[i]=Val[i];
for (int i=; i<=m; ++i)
{
scanf("%d%d%d",&opt,&x,&y);
if (opt==) Query(x,y);
if (opt== && Find_root(x)!=Find_root(y)) Link(x,y);
if (opt== && Find_root(x)==Find_root(y)) Cut(x,y);
if (opt==) Access(x),Splay(x),Val[x]=y,Update(x);
}
}
3282. Tree【LCT】的更多相关文章
- [BZOJ 3282] Tree 【LCT】
题目链接:BZOJ - 3282 题目分析 这道题是裸的LCT,包含 Link , Cut 和询问两点之间的路径信息. 写代码时出现的错误:Access(x) 的循环中应该切断的是原来的 Son[x] ...
- BZOJ2631 tree 【LCT】
题目 一棵n个点的树,每个点的初始权值为1.对于这棵树有q个操作,每个操作为以下四种操作之一: + u v c:将u到v的路径上的点的权值都加上自然数c: - u1 v1 u2 v2:将树中原有的边( ...
- [BZOJ - 2631] tree 【LCT】
题目链接:BZOJ - 2631 题目分析 LCT,像线段树区间乘,区间加那样打标记. 这道题我调了一下午. 提交之后TLE了,我一直以为是写错了导致了死循环. 于是一直在排查错误.直到.. 直到我看 ...
- 606. Construct String from Binary Tree 【easy】
606. Construct String from Binary Tree [easy] You need to construct a string consists of parenthesis ...
- 【HDU4010】【LCT】Query on The Trees
Problem Description We have met so many problems on the tree, so today we will have a query problem ...
- 【BZOJ2049】【LCT】Cave 洞穴勘测
Description 辉 辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通 道组成,并且每条通道连接了 ...
- 543. Diameter of Binary Tree【Easy】【二叉树的直径】
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...
- 3282: Tree(LCT)
3282: Tree Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 2249 Solved: 1042[Submit][Status][Discus ...
- 【BZOJ】3282: Tree(lct)
http://www.lydsy.com/JudgeOnline/problem.php?id=3282 复习了下lct,发现两个问题.. 1:一开始我以为splay那里直接全部rot(x)就好了,然 ...
随机推荐
- swagger 集成asp.net Core2.1
首先通过nuget 安装 Swashbuckle.AspNetCore 1.在startup.cs 的configureService services.AddAutoMapper(); serv ...
- 现代 C++ 编译时 结构体字段反射
基于 C++ 14 原生语法,不到 100 行代码:让编译器帮你写 JSON 序列化/反序列化代码,告别体力劳动.
- 小tip:FireFox下文本框/域百分比padding bug解决——张鑫旭
一.问题描述 我是流体布局控,经常会遇到文本框以及文本域宽度100%自适应显示的情况. 如下效果图: 在窄屏下,上面的文本框宽度也要跟着外部宽度变小. 难点对于文本框或者文本域,光标最好距离左侧边缘有 ...
- yii 修改模块使用的布局文件
方法一:yii模块默认使用系统当前的主题布局文件,如果在主配置文件中配置了主题比如: 'theme'=>'mythm', 那么yii的模块就使用 protected/themes/mythm/v ...
- 用localStorage来存储数据的一些经验
localStorage: 是一种你不主动清除它,它会一直将存储数据存储在客户端的存储方式,即使你关闭了客户端(浏览器),属于本地持久层储存 sessionStorage: 用于本地存储一个会话(se ...
- Spring Boot—12URL映射
package com.sample.smartmap.controller; import java.util.List; import org.springframework.beans.fact ...
- Session、Cookie简单理解
Session: session是一种记录客户状态的机制,session是保存在服务器上的,当浏览器访问服务器的时候,服务器把客户端信息以某种形式记录在服务器上,这就是所谓的session,当浏览器再 ...
- 【java8】慎用java8的foreach循环(作废)
+警告 这篇文章作废掉,是由一个错误的测试方法得到的一个错误结论,后续修正结果正在测试,将贴上. 准确测试已完成:http://www.cnblogs.com/yiwangzhibujian/p/69 ...
- MYSQL数据类型 表基本操作 表记录增删改 单表查询
一.数据类型 常用的数据类型如下: 整数:int,bit 小数:decimal 字符串:varchar,char 日期时间: date, time, datetime 枚举类型(enum) 特别说明的 ...
- Oracle AP更新供应商
/*l_return_status:S l_msg_count:0 l_msg_data: l_vendor_id:133003 l_party_id:236055 */ DECLARE l_ ...