@@ -24,9 +24,14 @@ public class Code01_PersistentUnionFind1 {
2424 public static int MAXT = 8000001 ;
2525 public static int n , m ;
2626
27- // 可持久化线段树
27+ // rootfa[i] = j,表示father数组,i版本的头节点编号为j
2828 public static int [] rootfa = new int [MAXM ];
29+
30+ // rootsiz[i] = j,表示siz数组,i版本的头节点编号为j
2931 public static int [] rootsiz = new int [MAXM ];
32+
33+ // 可持久化father数组和可持久化siz数组,共用一个ls、rs、val
34+ // 因为可持久化时,分配的节点编号不同,所以可以共用
3035 public static int [] ls = new int [MAXT ];
3136 public static int [] rs = new int [MAXT ];
3237 public static int [] val = new int [MAXT ];
@@ -58,7 +63,9 @@ public static int buildsiz(int l, int r) {
5863 return rt ;
5964 }
6065
61- // 来自讲解157,题目1,修改数组中一个位置的值,生成新版本的树
66+ // 来自讲解157,题目1,修改数组中一个位置的值,生成新版本的数组
67+ // 如果i属于可持久化father数组的节点,那么修改的就是father数组
68+ // 如果i属于可持久化siz数组的节点,那么修改的就是siz数组
6269 public static int update (int jobi , int jobv , int l , int r , int i ) {
6370 int rt = ++cnt ;
6471 ls [rt ] = ls [i ];
@@ -77,6 +84,8 @@ public static int update(int jobi, int jobv, int l, int r, int i) {
7784 }
7885
7986 // 来自讲解157,题目1,查询数组中一个位置的值
87+ // 如果i属于可持久化father数组的节点,那么查询的就是father数组
88+ // 如果i属于可持久化siz数组的节点,那么查询的就是siz数组
8089 public static int query (int jobi , int l , int r , int i ) {
8190 if (l == r ) {
8291 return val [i ];
@@ -99,7 +108,7 @@ public static int find(int x, int v) {
99108 return x ;
100109 }
101110
102- // 基于v版本,合并x所在的集合和y所在的集合,生成新版本的树
111+ // 基于v版本,合并x所在的集合和y所在的集合,生成新版本的数组
103112 public static void union (int x , int y , int v ) {
104113 int fx = find (x , v );
105114 int fy = find (y , v );
0 commit comments