MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / query

Method query

src/class184/Code02_Difficult1.java:123–136  ·  view source on GitHub ↗
(long[] tree, int jobl, int jobr, int l, int r, int i)

Source from the content-addressed store, hash-verified

121 }
122
123 public static long query(long[] tree, int jobl, int jobr, int l, int r, int i) {
124 if (jobl <= l && r <= jobr) {
125 return tree[i];
126 }
127 int mid = (l + r) >> 1;
128 long ans = -INF;
129 if (jobl <= mid) {
130 ans = Math.max(ans, query(tree, jobl, jobr, l, mid, i << 1));
131 }
132 if (jobr > mid) {
133 ans = Math.max(ans, query(tree, jobl, jobr, mid + 1, r, i << 1 | 1));
134 }
135 return ans;
136 }
137
138 // 得到子树大小递归版,java会爆栈,C++可以通过
139 public static void getSize1(int u, int fa) {

Callers 1

calcMethod · 0.95

Calls 1

maxMethod · 0.45

Tested by

no test coverage detected