Rope Tutorial: http://blog.csdn.net/iamzky/article/details/38348653
Code (bzoj3673 ):
1 # include <cstdio> 2 # include <EXT/rope> 3 using namespace STD; 4 using namespace _ gnu_cxx; 5 rope <int> * Fa [20001]; 6 int A, B, n, m, a [20001], OP; 7 int root (INT num, int X) 8 {9 If (Fa [num]-> at (x) = x) 10 return X; 11 int RT = root (Num, fa [num]-> at (x); 12 // If (RT = Fa [num]-> at (x) without adding the two rows, bzoj3674 will blow up the memory. 13 14 // return RT; 15 Fa [num]-> Replace (x, RT); 16 return RT; 17} 18 void Union (INT num, int X, int y) 19 {20 int u = root (Num, x), V = root (Num, Y); 21 Fa [num]-> Replace (v, U ); 22} 23 int main () 24 {25 scanf ("% d", & N, & M); 26 for (INT I = 1; I <= N; I ++) 27 A [I] = I; 28 Fa [0] = new rope <int> (A, A + n + 1 ); 29 for (INT I = 1; I <= m; I ++) 30 {31 Fa [I] = new rope <int> (* Fa [I-1]); 32 scanf ("% d", & OP); 33 If (OP = 1) {scanf ("% d", & A, & B ); union (I, a, B);} 34 else if (OP = 2) {scanf ("% d", & ); fa [I] = Fa [a];} 35 else {scanf ("% d", & A, & B); printf ("% d \ n ", root (I, A) = root (I, B);} 36} 37 return 0; 38}
[Persistent array] [Rope] bzoj3673 bzoj3674 persistent and query set by zky