分析

代码

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define _(x) int x
#define mp make_pair
#define pr pair<int,int>
int fa[],son[][],a[],siz[],r[];
inline void up(int x){siz[x]=siz[son[x][]]+siz[son[x][]]+;return;}
inline void rev(int x){swap(son[x][],son[x][]);r[x]^=;return;}
inline void pd(int x){if(r[x]){for(_(i)=;i<;i++)if(son[x][i])rev(son[x][i]);r[x]=;}return;}
inline int notroot(int x){return x==son[fa[x]][]||x==son[fa[x]][];}
inline void pushall(int x){if(notroot(x))pushall(fa[x]);pd(x);return;}
inline int gs(int x){return x==son[fa[x]][];}
inline void rot(int x){
int y=fa[x],z=fa[y],b=gs(x),c=gs(y),d=son[x][!b];
if(notroot(y))son[z][c]=x;
fa[x]=z;if(d)fa[d]=y;
son[y][b]=d,son[x][!b]=y;
fa[y]=x;up(y),up(x);return;
}
inline void splay(int x){
pushall(x);
while(notroot(x)){
int y=fa[x],z=fa[y];
if(notroot(y)){
if(gs(x)==gs(y))rot(y);
else rot(x);
}
rot(x);
}
return;
}
inline void access(int x){for(int y=;x;y=x,x=fa[x])splay(x),son[x][]=y,up(x);return;}
inline void makeroot(int x){access(x),splay(x),rev(x);return;}
inline void spt(int x,int y){makeroot(x),access(y),splay(y);return;}
inline void link(int x,int y){makeroot(x);fa[x]=y;return;}
pr d[];
int n,m,q,f[],p1,p2,mx;
inline int sf(int x){return f[x]==x?x:f[x]=sf(f[x]);}
inline void work(int x,int y){
spt(x,y);int res=siz[y]-;
if(res>mx)mx=res,p1=x,p2=y;
return;
}
inline void mer(int x,int y){
pr a=d[sf(x)],b=d[sf(y)];
mx=;link(x,y);
work(a.fi,a.se),work(b.fi,b.se);
work(a.fi,b.fi),work(a.fi,b.se);
work(a.se,b.fi),work(a.se,b.se);
f[sf(x)]=sf(y);d[sf(y)]=mp(p1,p2);
return;
}
inline int que(int x){
pr a=d[sf(x)];
int res=;
spt(a.fi,x),res=max(res,siz[x]-);
spt(a.se,x),res=max(res,siz[x]-);
return res;
}
int main(){
int i,j,k,la=,opt,x,y;
scanf("%d%d%d",&opt,&n,&q);
for(i=;i<=n;i++)f[i]=i,d[i]=mp(i,i),siz[i]=;
while(q--){
scanf("%d",&k);
if(k==)scanf("%d%d",&x,&y);
else scanf("%d",&x);
x^=(la*opt),y^=(la*opt);
if(k==)mer(x,y);
else printf("%d\n",la=que(x));
}
return ;
}

loj#6038 「雅礼集训 2017 Day5」远行的更多相关文章

  1. LOJ#6038. 「雅礼集训 2017 Day5」远行(LCT)

    题面 传送门 题解 要不是因为数组版的\(LCT\)跑得实在太慢我至于去学指针版的么--而且指针版的完全看不懂啊-- 首先有两个结论 1.与一个点距离最大的点为任意一条直径的两个端点之一 2.两棵树之 ...

  2. 【刷题】LOJ 6038 「雅礼集训 2017 Day5」远行

    题目描述 Miranda 生活的城市有 \(N\) 个小镇,一开始小镇间没有任何道路连接.随着经济发现,小镇之间陆续建起了一些双向的道路但是由于经济不太发达,在建设过程中,会保证对于任意两个小镇,最多 ...

  3. LOJ#6038. 「雅礼集训 2017 Day5」远行 [LCT维护子树的直径]

    树的直径一定是原联通块4个里的组合 1.LCT,维护树的直径,这题就做完了 2.直接倍增,lca啥的求求距离,也可以吧- // powered by c++11 // by Isaunoya #inc ...

  4. [LOJ#6039].「雅礼集训 2017 Day5」珠宝[决策单调性]

    题意 题目链接 分析 注意到本题的 \(C\) 很小,考虑定义一个和 \(C\) 有关的状态. 记 \(f(x,j)\) 表示考虑到了价格为 \(x\) 的物品,一共花费了 \(j\) 元的最大收益. ...

  5. loj#6040. 「雅礼集训 2017 Day5」矩阵(线性代数+递推)

    题面 传送门 题解 我的线代学得跟屎一样看题解跟看天书一样所以不要指望这题我会写题解 这里 //minamoto #include<bits/stdc++.h> #define R reg ...

  6. @loj - 6039@ 「雅礼集训 2017 Day5」珠宝

    目录 @description@ @solution@ @accpeted code@ @details@ @description@ Miranda 准备去市里最有名的珠宝展览会,展览会有可以购买珠 ...

  7. loj #6039 「雅礼集训 2017 Day5」珠宝 分组背包 决策单调性优化

    LINK:珠宝 去年在某个oj上写过这道题 当时懵懂无知wa的不省人事 终于发现这个东西原来是有决策单调性的. 可以发现是一个01背包 但是过不了 冷静分析 01背包的复杂度有下界 如果过不了说明必然 ...

  8. loj6038「雅礼集训 2017 Day5」远行 树的直径+并查集+LCT

    题目传送门 https://loj.ac/problem/6038 题解 根据树的直径的两个性质: 距离树上一个点最远的点一定是任意一条直径的一个端点. 两个联通块的并的直径是各自的联通块的两条直径的 ...

  9. 【loj6038】「雅礼集训 2017 Day5」远行 树的直径+并查集+LCT

    题目描述 给你 $n$ 个点,支持 $m$ 次操作,每次为以下两种:连一条边,保证连完后是一棵树/森林:询问一个点能到达的最远的点与该点的距离.强制在线. $n\le 3\times 10^5$ ,$ ...

随机推荐

  1. jstl用法 简介

    <c:choose> <c:when test="${salary <= 0}"> 太惨了. </c:when> <c:when t ...

  2. OpenSSL使用小结

    引言 互联网的发展史上,安全性一直是开发者们相当重视的一个主题,为了实现数据传输安全,我们需要保证:数据来源(非伪造请求).数据完整性(没有被人修改过).数据私密性(密文,无法直接读取)等.虽然现在已 ...

  3. 判断浏览器类型JS

    // 判断浏览器类型 getExplorer() { var explorer = window.navigator.userAgent, compare = function (s) { retur ...

  4. Windows 下apache https配置(phpstudy)

    1.首先获取证书,https://www.pianyissl.com/  免费三个月的 或者 自己生成私钥.证书,然后应用到apache中. http://blog.sina.com.cn/s/blo ...

  5. java.lang.IllegalStateException: No output folder

    将正在正常运行的tomcat打包(使用tar -zcvf命令打的包),然后放到其他服务器上使用非root用户解压(使用tar -zxvf命令)配置好之后,启动tomcat后报错如下 HTTP Stat ...

  6. k8s第一个脚本:hello world

    1.hello-world-pod.yaml 脚本: # cat hello-world-pod.yaml apiVersion: v1 kind: Pod metadata: name: hello ...

  7. linux新建用户并分配sudo权限

    新建用户 useradd [username] 给用户设置密码 passwd [username] 设置sudo权限 首先将sudoers权限设置可写入 chmod u+w /etc/sudoers ...

  8. Git 查看远端仓库地址

    git remote -v

  9. 最简单的Android项目(含有资源文件)

    上次的项目没有使用资源文件,打包出的apk安装后是系统默认图标,程序标题也是包名加类名. 添加资源需要对编译的命令做一点调整. 首先在项目根目录新建res和assets目录,在res内新建drawab ...

  10. 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)

    链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...