1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| #include <iostream> #include <math.h> #include <string> #include <stdio.h> #include <string.h> #include <algorithm> #include <vector> using namespace std;
#define ll long long #define sc1(a) scanf("%lld",&a) #define sc2(a,b) scanf("%lld %lld",&a,&b) #define lson(x) x<<1 #define rson(x) x<<1|1 #define lowbit(x) (x&(-x)) #define fuck(x) cout<<"[Debug : "<<#x<<" "<<(x)<<']'<<endl
const int maxn = 2e5+7; const int maxm = 2500010; vector<int> vv; int getid(int x){return (int)(lower_bound(vv.begin(),vv.end(),x)-vv.begin())+1;}
struct node{ int l,r,val; }T[maxn * 40]; int tot,m,n; void build(int &x,int l,int r) { x=++tot;T[x].val = 0; if(l == r){T[x].val = l;return;} int mid = (l+r)>>1; build(T[x].l,l,mid); build(T[x].r,mid+1,r); } void update(int y,int &x,int l,int r,int pos,int val) { x=++tot;T[x]=T[y]; if(l == r){ T[x].val = val; return ; } int mid = (l+r)>>1; if(pos<=mid)update(T[y].l,T[x].l,l,mid,pos,val); else update(T[y].r,T[x].r,mid+1,r,pos,val); } int query(int x,int l,int r,int pos) { if(l==r)return T[x].val; int mid = (l + r) >> 1; if(mid >= pos)return query(T[x].l,l,mid,pos); else return query(T[x].r,mid+1,r,pos); }
int opt[maxn]; int aa,bb,kk; int tmp; int getfa(int x,int now) { return query(x,1,n,now); }
int setfa(int x,int pos,int val) { update(x,tmp,1,n,pos,val); return tmp; }
int find(int &rt,int x) { int fx = getfa(rt,x); if(fx == x)return x; else{ fx = find(rt,fx); rt = setfa(rt,x,fx); return fx; } }
void merge(int &rt,int x,int y) { int fx = find(rt,x); int fy = find(rt,y); if(fx != fy){ rt = setfa(rt,fx,fy); } } int main() { scanf("%d%d",&n,&m); n ++; build(opt[0],1,n); int lastans = 0; for(int i = 1;i<=m;i++) { opt[i] = opt[i-1]; int oo;scanf("%d",&oo); if(oo == 1){ scanf("%d%d",&aa,&bb); aa = aa ^ lastans; bb = bb ^ lastans; aa ++;bb ++; merge(opt[i],aa,bb); }else if( oo == 2 ){ scanf("%d",&kk); kk = kk ^ lastans; opt[i] = opt[kk]; }else{ scanf("%d%d",&aa,&bb); aa = aa ^ lastans; bb = bb ^ lastans; aa ++; bb ++; int fx = find(opt[i],aa); int fy = find(opt[i],bb); if(fx == fy)lastans = 1; else lastans = 0; printf("%d\n",lastans); } }
}
|