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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
| #include<algorithm> #include<bitset> #include<complex> #include<deque> #include<exception> #include<fstream> #include<functional> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<iterator> #include<limits> #include<list> #include<locale> #include<map> #include<memory> #include<new> #include<numeric> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<typeinfo> #include<utility> #include<valarray> #include<vector> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<cmath> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> using namespace std;
#define re register #define LD double
#define gc getchar #define mod 100000007 #define MAXN 400010*18
class Quick_Input_Output{ private: static const int S=1<<21; #define tc() (A==B&&(B=(A=Rd)+fread(Rd,1,S,stdin),A==B)?EOF:*A++) char Rd[S],*A,*B; #define pc putchar public:
inline int read(){ int res=0,f=1;char ch=gc(); while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=gc();} while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=gc(); return res*f; } inline void write(int x){ if(x<0) pc('-'),x=-x; if(x<10) pc(x+'0'); else write(x/10),pc(x%10+'0'); }
#undef pc }I; #define File freopen("4399.in","r",stdin);freopen("4399.out","w",stdout);
struct Question{int id,x,y;}q[MAXN]; int m,cnt;
class Discretization{ public: int lsh[MAXN],n; inline void init(){ for(int i=1;i<=m;i++){ if(q[i].id==3q[i].id==4) lsh[++n]=q[i].y; if(q[i].id==1) lsh[++n]=q[i].x; } sort(lsh+1,lsh+n+1); n=unique(lsh+1,lsh+n+1)-(lsh+1); } inline int getlsh(int x){ return lower_bound(lsh+1,lsh+n+1,x)-lsh; } }L;
class Segment_tree{ public: int rt[MAXN],sz[MAXN],son[MAXN][2],tag[MAXN],tot; LD sum[MAXN]; inline void Upd(int x){ sz[x]=sz[son[x][0]]+sz[son[x][1]]; sum[x]=sum[son[x][0]]+sum[son[x][1]]; } inline void Psd(int x){ if(tag[x]==0) return ; tag[son[x][0]]=1;sz[son[x][0]]=sum[son[x][0]]=0; tag[son[x][1]]=1;sz[son[x][1]]=sum[son[x][1]]=0; tag[x]=0; } inline void insert(int x,int l,int r,int now,int sm,LD logsum){ re int mid=l+r>>1; Psd(x); if(l==r){ sz[x]=sm; sum[x]=logsum; return ; } if(now<=mid) insert(son[x][0]==0?son[x][0]=++tot:son[x][0],l,mid,now,sm,logsum); else insert(son[x][1]==0?son[x][1]=++tot:son[x][1],mid+1,r,now,sm,logsum); Upd(x); } inline int merge(int x,int y,int l,int r){ if(x==0y==0) return x+y; sum[x]+=sum[y]; sz[x]+=sz[y]; re int mid=l+r>>1; if(l==r) return x; Psd(x);Psd(y); son[x][0]=merge(son[x][0],son[y][0],l,mid); son[x][1]=merge(son[x][1],son[y][1],mid+1,r); return x; } inline int query(int x,int l,int r,int L,int R){ if(x==0) return 0; if(L<=l&&r<=R) return sz[x]; re int mid=l+r>>1; Psd(x); re int s=0; if(L<=mid) s+=query(son[x][0],l,mid,L,R); if(R>mid) s+=query(son[x][1],mid+1,r,L,R); return s; } inline void add(int x,int l,int r,int L,int R){ if(x==0) return ; if(L<=l&&r<=R){ sum[x]=sz[x]=0; tag[x]=1; return ; } re int mid=l+r>>1; Psd(x); if(L<=mid) add(son[x][0],l,mid,L,R); if(R>mid) add(son[x][1],mid+1,r,L,R); Upd(x); } inline int getsz(int now,int l,int r,int x){ if(l==r) return L.lsh[l]; re int mid=l+r>>1; Psd(now); if(sz[son[now][0]]>=x) return getsz(son[now][0],l,mid,x); else return getsz(son[now][1],mid+1,r,x-sz[son[now][0]]); } }T;
class Union_Checking_Set{ public: int fa[MAXN]; inline int getfa(int x){ return x==fa[x]?x:fa[x]=getfa(fa[x]); } inline void merge(int x,int y){ x=getfa(x);y=getfa(y); if(x==y) return ; fa[y]=x;T.rt[x]=T.merge(T.rt[x],T.rt[y],1,L.n); } }U;
class Solve{ public: inline void init(){ m=I.read(); for(int i=1;i<=m;i++){ q[i].id=I.read(); if(q[i].id==1q[i].id==7) q[i].x=I.read(); else q[i].x=I.read(),q[i].y=I.read(); } L.init(); } inline void solve(){ for(int x,y,s,i=1;i<=m;i++){ switch(q[i].id){ case 1:++cnt,T.insert(T.rt[cnt]==0?T.rt[cnt]=++T.tot:T.rt[cnt],1,L.n,L.getlsh(q[i].x),1,log2(q[i].x)),U.fa[cnt]=cnt;break; case 2:U.merge(q[i].x,q[i].y);break; case 3:x=U.getfa(q[i].x),y=L.getlsh(q[i].y),s=T.query(T.rt[x],1,L.n,1,y),T.add(T.rt[x],1,L.n,1,y),T.insert(T.rt[x]==0?T.rt[x]=++T.tot:T.rt[x],1,L.n,y,s,s*log2(q[i].y));break; case 4:x=U.getfa(q[i].x),y=L.getlsh(q[i].y),s=T.query(T.rt[x],1,L.n,y,L.n),T.add(T.rt[x],1,L.n,y,L.n),T.insert(T.rt[x]==0?T.rt[x]=++T.tot:T.rt[x],1,L.n,y,s,s*log2(q[i].y));break; case 5:I.write(T.getsz(T.rt[U.getfa(q[i].x)],1,L.n,q[i].y)),putchar('\n');break; case 6:I.write(T.sum[T.rt[U.getfa(q[i].x)]]>T.sum[T.rt[U.getfa(q[i].y)]]?1:0),putchar('\n');break; default:I.write(T.sz[T.rt[U.getfa(q[i].x)]]),putchar('\n');break; } } } }S;
int main(){ File S.init(); S.solve(); return 0; }
|