看到值最大为60,我们可以想到状态压缩,把60个值全部压成二进制。每次动态连接,求链上或的和。

当然我们可以离线去树剖,用线段树维护。

但是对于会LCT的人,当然我们要用LCT啦,直接LCT维护链上或的和就好了。

AC代码:

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define ls(x) t[x].ch[0]
#define rs(x) t[x].ch[1]
const int N=1e5+10;
int cnt,st[N],n,q;
struct node{int ch[2],fa,re,val,col;
}t[N];
inline void push_up(int p){t[p].val=t[ls(p)].val|t[rs(p)].val|(1LL<<t[p].col);
}
inline void push_re(int p){swap(ls(p),rs(p)); t[p].re^=1;}
inline void push_down(int p){if(!t[p].re)   return;if(ls(p))    push_re(ls(p)); if(rs(p))   push_re(rs(p)); t[p].re^=1;
}
inline bool isroot(int x){return ls(t[x].fa)!=x&&rs(t[x].fa)!=x;}
inline void rotate(int x){int y=t[x].fa,z=t[y].fa,k=rs(y)==x,w=t[x].ch[!k];if(!isroot(y)) t[z].ch[rs(z)==y]=x; t[x].ch[!k]=y; t[y].ch[k]=w;if(w) t[w].fa=y; t[y].fa=x; t[x].fa=z; push_up(y);
}
inline void splay(int x){cnt=1;    st[cnt]=x; int y=x;while(!isroot(y))  st[++cnt]=y=t[y].fa;while(cnt)  push_down(st[cnt--]);while(!isroot(x)){int y=t[x].fa,z=t[y].fa;if(!isroot(y)) rotate((ls(y)==x)^(ls(z)==y)?x:y); rotate(x);}push_up(x);
}
inline void access(int x){for(int y=0;x;x=t[y=x].fa) splay(x),rs(x)=y,push_up(x);
}
inline void makeroot(int x){access(x); splay(x); push_re(x);
}
inline int find(int x){access(x); splay(x); while(ls(x)) push_down(x),x=ls(x); splay(x);   return x;
}
inline void split(int x,int y){makeroot(x); access(y); splay(y);
}
inline void link(int x,int y){if(find(x)==find(y))    return ;int tc=t[x].col+t[y].col>>1;makeroot(x),t[x].fa=y,t[x].col=tc,makeroot(y),t[y].col=tc;
}
inline void cut(int x,int y){makeroot(x); if(find(y)==x&&t[y].fa==x&&!ls(y)) t[y].fa=rs(x)=0,push_up(x);
}
inline int ask(int x,int y){if(find(x)!=find(y))   return -1;split(x,y);   int tc=t[y].val,res=0;for(;tc;tc-=tc&(-tc))  res++;return res;
}
signed main(){cin>>n>>q;for(int i=1;i<=n;i++)    cin>>t[i].col;for(int i=1,op,x,y;i<=q;i++){scanf("%lld %lld %lld",&op,&x,&y);if(op==1) link(x,y);else  printf("%lld\n",ask(x,y));}return 0;
}

Chino with Rewrite相关推荐

  1. nginx rewrite 指令last break区别最详细的解释

    总结: rewrite 可以在 server location 块, 正则比配的时候才重写,所以多条 rewrite 顺序靠前且匹配的优先执行. break跳出rewrite阶段,不会在匹配,进入输出 ...

  2. rewrite or internal redirection cycle while processing nginx重定向报错

    2018/05/07 15:03:42 [error] 762#0: *3 rewrite or internal redirection cycle while processing "/ ...

  3. Nginx rewrite正则匹配重写

    Nginx的rewrite功能支持正则匹配重写,即将URL地址临时或永久重新指向某个新的位置,类似于重定向.这个特性有利用当网站结构做出重大调整,如之前的网站mp3资源使用URL为www.site1. ...

  4. NGINX中的proxy_pass和rewrite

    rewrite syntax: rewrite regex replacement [flag] Default: - Context: server, location, if 如果正则表达式(re ...

  5. nginx生产环境常用功能include 、虚拟主机别名、rewrite、nginx status详细解析

    一.配置文件优化之include参数 如果我们用nginx搭建虚拟主机,虚拟主机太多,我们不能把所有配置放置在nginx.conf中吧?那样这个配置文件就太大了,看起来很乱,所有这时就产生了 incl ...

  6. Apache Rewrite url重定向功能的简单配置

    1.Apache Rewrite的主要功能 就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范.平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等 2.Apache Rewrite ...

  7. Nginx 进阶 (ssl、fpm、rewrite、cache配置等)

    一.配置https网站 1.自建CA (1)生成私钥文件 mkdir -p /etc/pki/CA/private #创建私钥保存的目录 (umask 077;openssl genrsa -out ...

  8. nginx rewrite重写与防盗链配置

    nginx rewrite重写规则与防盗链配置方法 时间:2016-02-04 15:16:58来源:网络 导读:nginx rewrite重写规则与防盗链配置方法,rewrite规则格式中flag标 ...

  9. nginx rewrite和根据url参数location

    最近项目中涉及到旧老项目迁移,需要在nginx上做些配置,所以简单学习了下,好记性不如烂笔头,先记下来. rewrite 首先查看下nginx是否支持rewrite: ./nginx -V 不支持说明 ...

最新文章

  1. L2:grep使用正则表达式
  2. git配置用户名和密码_IDEA配置码云教程
  3. 下拉加载 实现 java_[Java教程]iscroll5实现一个下拉刷新上拉加载的效果
  4. 建立数字化、学习型人事平台,HR 与业务终于不再「隔空对话」
  5. 一些服务器客户端的c例子
  6. 关于运行jar包时的一个错误
  7. Django之Apache2部署
  8. SQL优化--使用关联查询代替子查询
  9. J2EE实战开发Android项目视频教程
  10. django ajax 简书,Django中ajax上传图片详细步骤
  11. 情人节浪漫3D照片墙【附源码】
  12. 图鉴|春节怼亲戚指南(2020版)
  13. c/c++中的内存分配器
  14. miui 9 android pay,小米9多功能NFC再升级,Mi Pay线上支付上线
  15. python识别文字软件_【Python 教程】使用 Python 和大漠插件进行文字识别
  16. Sublime Text 中文版安装和插件安装
  17. hdu 4389 X mod f(x) (数位dp||打表)
  18. 房贷新政冷冻楼市 炒楼热钱流向股市
  19. 串口助手发送数据到单片机并显示在液晶上
  20. element is not attached to the page document报错解决办法

热门文章

  1. 9 WebMagic 入门案例
  2. iphone5s 越狱 绕过icolud
  3. 递归实现n阶螺旋矩阵问题
  4. ubuntu18.04 terminal 无法打开
  5. PTA刷题Basic篇——1051.复数乘法——Day(26)
  6. 基于IC617创建保护环GuardRing(一)
  7. 计算机网络--数据链路层[微课堂]
  8. 磷酸铁锂电池回收浸出液除铝
  9. GSA 8月最新5G报告:全球已发布100台5G设备
  10. 梦幻西游手游排队显示服务器已满,梦幻西游手游排队进不去 一直排队解决方法...