<题意概括>
又是一道可持久化并查集的裸题
一开始以为和[BZOJ 3673]一样
受到Description的启发觉得要路径压缩
但是想了一下觉得修改的时间复杂度更大
于是本蒟蒻Ctrl+V后加上LastAns就交了
结果不出意料地光荣TLE
路径压缩后就AC了..
果然我还是太Naive了
<做法>
在[BZOJ 3673]的基础上加上路径压缩就行了
<Code>
#include<cstdio> #define Fast register inline char Getchar(){ static char BUF[16384],*S=BUF,*T=BUF; return(S==T)&&(T=(S=BUF)+fread(BUF,1,16384,stdin),S==T)?EOF:*S++; } inline int Getint(){ Fast int s=0;Fast char c=Getchar(),w=0; while(c<48||c>57)c==45&&(w=1),c=Getchar(); while(c>47&&c<58)s=s*10+c-48,c=Getchar(); return w?-s:s; } struct Node{ int key; Node *lson,*rson; Node(int key=0):key(key){} Node(Node*&o):key(o->key),lson(o->lson),rson(o->rson){} }*root[200001]; #define ls(o) (o)->lson #define rs(o) (o)->rson inline void Build(Node*&o,const int&L,const int&R){ o=new Node; if(L==R){o->key=L;return;} Fast int Mid=(L+R)>>1; Build(ls(o),L,Mid); Build(rs(o),Mid+1,R); } inline void Modify(Node*&PostVersion,Node*&NewVersion,int L,int R,const int&Loc,const int&key){ Fast Node**Post=&PostVersion,**New=&NewVersion; Fast int Mid; while(L!=R){ Mid=(L+R)>>1; *New=new Node(*Post); if(Loc<=Mid)Post=&(ls(*Post)),New=&(ls(*New)),R=Mid; else Post=&(rs(*Post)),New=&(rs(*New)),L=Mid+1; } *New=new Node(*Post); (*New)->key=key; } inline int Query(Node*Version,int L,int R,const int&k){ Fast int Mid; while(L!=R){ Mid=(L+R)>>1; if(k<=Mid)Version=ls(Version),R=Mid; else Version=rs(Version),L=Mid+1; } return Version->key; } int N; inline int Find(Node*&Version,const int&Loc){ Fast int Fa=Query(Version,1,N,Loc),Ancestry; return Fa==Loc?Fa:(Modify(Version,Version,1,N,Loc,Ancestry=Find(Version,Fa)),Ancestry); } #define UnionSet(PostVersion,NewVersion,x,y) Modify(PostVersion,NewVersion,1,N,Find(PostVersion,x),Find(PostVersion,y)) inline bool SameSet(Node*&Version,const int&x,const int&y){return Find(Version,x)==Find(Version,y);} int main(){ N=Getint(); Fast int M=Getint(),opt,A,B,LastAns=0; Build(*root,1,N); for(Fast int i=1;i<=M;++i){ opt=Getint(),A=Getint()^LastAns; if(opt==1)UnionSet(root[i-1],root[i],A,Getint()^LastAns); else if(opt==2)root[i]=root[A]; else putchar((LastAns=SameSet(root[i]=root[i-1],A,Getint()^LastAns))+48),putchar(10); } }