分析

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5. #define _(x) int x
  6. #define mp make_pair
  7. #define pr pair<int,int>
  8. int fa[],son[][],a[],siz[],r[];
  9. inline void up(int x){siz[x]=siz[son[x][]]+siz[son[x][]]+;return;}
  10. inline void rev(int x){swap(son[x][],son[x][]);r[x]^=;return;}
  11. inline void pd(int x){if(r[x]){for(_(i)=;i<;i++)if(son[x][i])rev(son[x][i]);r[x]=;}return;}
  12. inline int notroot(int x){return x==son[fa[x]][]||x==son[fa[x]][];}
  13. inline void pushall(int x){if(notroot(x))pushall(fa[x]);pd(x);return;}
  14. inline int gs(int x){return x==son[fa[x]][];}
  15. inline void rot(int x){
  16. int y=fa[x],z=fa[y],b=gs(x),c=gs(y),d=son[x][!b];
  17. if(notroot(y))son[z][c]=x;
  18. fa[x]=z;if(d)fa[d]=y;
  19. son[y][b]=d,son[x][!b]=y;
  20. fa[y]=x;up(y),up(x);return;
  21. }
  22. inline void splay(int x){
  23. pushall(x);
  24. while(notroot(x)){
  25. int y=fa[x],z=fa[y];
  26. if(notroot(y)){
  27. if(gs(x)==gs(y))rot(y);
  28. else rot(x);
  29. }
  30. rot(x);
  31. }
  32. return;
  33. }
  34. inline void access(int x){for(int y=;x;y=x,x=fa[x])splay(x),son[x][]=y,up(x);return;}
  35. inline void makeroot(int x){access(x),splay(x),rev(x);return;}
  36. inline void spt(int x,int y){makeroot(x),access(y),splay(y);return;}
  37. inline void link(int x,int y){makeroot(x);fa[x]=y;return;}
  38. pr d[];
  39. int n,m,q,f[],p1,p2,mx;
  40. inline int sf(int x){return f[x]==x?x:f[x]=sf(f[x]);}
  41. inline void work(int x,int y){
  42. spt(x,y);int res=siz[y]-;
  43. if(res>mx)mx=res,p1=x,p2=y;
  44. return;
  45. }
  46. inline void mer(int x,int y){
  47. pr a=d[sf(x)],b=d[sf(y)];
  48. mx=;link(x,y);
  49. work(a.fi,a.se),work(b.fi,b.se);
  50. work(a.fi,b.fi),work(a.fi,b.se);
  51. work(a.se,b.fi),work(a.se,b.se);
  52. f[sf(x)]=sf(y);d[sf(y)]=mp(p1,p2);
  53. return;
  54. }
  55. inline int que(int x){
  56. pr a=d[sf(x)];
  57. int res=;
  58. spt(a.fi,x),res=max(res,siz[x]-);
  59. spt(a.se,x),res=max(res,siz[x]-);
  60. return res;
  61. }
  62. int main(){
  63. int i,j,k,la=,opt,x,y;
  64. scanf("%d%d%d",&opt,&n,&q);
  65. for(i=;i<=n;i++)f[i]=i,d[i]=mp(i,i),siz[i]=;
  66. while(q--){
  67. scanf("%d",&k);
  68. if(k==)scanf("%d%d",&x,&y);
  69. else scanf("%d",&x);
  70. x^=(la*opt),y^=(la*opt);
  71. if(k==)mer(x,y);
  72. else printf("%d\n",la=que(x));
  73. }
  74. return ;
  75. }

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. java学习笔记(5)多线程

    一.简介(过段时间再写,多线程难度有点大) --------------------------------------- 1.进程:运行时的概念,运行的应用程序 2.线程:应用程序内部并发执行的代码 ...

  2. vue-cli常用插件安装教程

    1.安装sass npm i sass-loader node-sass --save-dev 2.安装stylus cnpm install stylus --save-dev cnpm insta ...

  3. python语音提示

    #coding:utf8 import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") whi ...

  4. 学习-Pytest(三)setup/teardown

    1. 用例运行级别 模块级(setup_module/teardown_module)开始于模块始末,全局的 函数级(setup_function/teardown_function)只对函数用例生效 ...

  5. python-字符编码的转换

    python-字符编码的转换 1.了解基础知识 ASCII  一个英文,占一个字节.只能存英文和特殊字符. gb2312 约可以存7000中文 gb1830 约可以存27000中文 gbk 默认中文, ...

  6. 页面中获取 iframe 中的值

    3.页面中获取 iframe 中的值 var obj=document.getElementsByClassName(".ke-edit-iframe").contentWindo ...

  7. AIX中crontab和at 定时任务

    1.crontab crontab文件用于在指定日期和时间周期性地执行作业 crontab 作业存放在/var/spool/cron/crontabs/$USER cron根据crontab文件项运行 ...

  8. MapReduce计数程序(自主复习)

    1.MyWordCount类 注意: 1.本机+测试,两个注释都放开 2.本机跑集群,要开异构平台为true 3.集群跑,把两个注释都注起来,然后在集群上面跑 package com.littlepa ...

  9. @ResponseBody 注解是什么意思?

    1. @ResponseBody注解的作用是将Controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML数据 ...

  10. linux shell鼠标键盘快捷键