Skip to content

Commit e5ac66c

Browse files
committed
modify code
1 parent f83161a commit e5ac66c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/class182/Code01_LeadersGroup1.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static void down(int i) {
7777
}
7878
}
7979

80+
// jobi来了个新值jobv,如果比之前获得的值更大就更新,否则不更新
8081
public static int update(int jobi, int jobv, int l, int r, int i) {
8182
int rt = i;
8283
if (rt == 0) {
@@ -97,6 +98,7 @@ public static int update(int jobi, int jobv, int l, int r, int i) {
9798
return rt;
9899
}
99100

101+
// 查询[jobl..jobr]范围上的最大值
100102
public static int query(int jobl, int jobr, int l, int r, int i) {
101103
if (i == 0) {
102104
return 0;
@@ -116,6 +118,8 @@ public static int query(int jobl, int jobr, int l, int r, int i) {
116118
return ans;
117119
}
118120

121+
// 线段树合并
122+
// max1代表dp[u][r+1...]的最大值,max2代表dp[v][r+1...]的最大值
119123
public static int merge(int l, int r, int t1, int t2, int max1, int max2) {
120124
if (t1 == 0 || t2 == 0) {
121125
if (t1 != 0) {
@@ -145,8 +149,10 @@ public static void dp(int u) {
145149
int v = to[e];
146150
dp(v);
147151
sum += query(arr[u], cntv, 1, cntv, root[v]);
152+
// 不选u的情况,每棵子树合并一遍
148153
root[u] = merge(1, cntv, root[u], root[v], 0, 0);
149154
}
155+
// 选u的情况,最后sum需要加1
150156
root[u] = update(arr[u], sum + 1, 1, cntv, root[u]);
151157
}
152158

0 commit comments

Comments
 (0)