Skip to content

Commit aec6cf7

Browse files
committed
Update content/5_Plat/Range_Sweep.mdx
1 parent 7ac1a95 commit aec6cf7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

content/5_Plat/Range_Sweep.mdx

+7-7
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,25 @@ int main() {
9797

9898
The first step is to create a DP to solve the first subtask. The states are the springboards and the transitions are between springboards. First, sort the springboards by the pair $(x_1, y_1)$ in increasing order. It is possible to show that for all $i$, $j$, where $i < j$, Bessie cannot use springboard $j$ then $i$ later.
9999

100-
For each springboard $i$, let $ans[i]$ denote the minimum distance needed to walk to the start point of springboard $i$.
100+
For each springboard $i$, let $\texttt{ans}[i]$ denote the minimum distance needed to walk to the start point of springboard $i$.
101101

102-
Let $dist(a, b)$ be the walking distance from the end of springboard $a$ and the start of springboard $b$.
102+
Let $\texttt{dist}(a, b)$ be the walking distance from the end of springboard $a$ and the start of springboard $b$.
103103

104-
$dist(a, b) = x_1[b] + y_1[b] - x_2[a] - y_2[a]$
104+
$\texttt{dist}(a, b) = x_1[b] + y_1[b] - x_2[a] - y_2[a]$
105105

106106
Then, the transitions are:
107107

108-
$ans[i] = \min\limits_{j < i, x_2[j] \le x_1[i], y_2[j] \le y_1[i]}(ans[j] + dist(j, i))$
108+
$\texttt{ans}[i] = \min\limits_{j < i, x_2[j] \le x_1[i], y_2[j] \le y_1[i]}(ans[j] + \texttt{dist}(j, i))$
109109

110110
**Full Solution:** $\mathcal{O}(P \log P)$
111111

112112
Optimizing the DP involves the use of a min point update range query segment tree. Let's first expand $dist(i, j)$ in the transition formula.
113113

114-
$ans[i] = \min\limits_{j < i, x_2[j] \le x_1[i], y_2[j] \le y_1[i]}(ans[j] + x_1[i] + y_1[i] - x_2[j] - y_2[j])$
114+
$\texttt{ans}[i] = \min\limits_{j < i, x_2[j] \le x_1[i], y_2[j] \le y_1[i]}(\texttt{ans}[j] + x_1[i] + y_1[i] - x_2[j] - y_2[j])$
115115

116-
$ans[i] = x_1[i] + y_1[i] + \min\limits_{j < i, x_2[j] \le x_1[i], y_2[j] \le y_1[i]}(ans[j] - x_2[j] - y_2[j])$
116+
$\texttt{ans}[i] = x_1[i] + y_1[i] + \min\limits_{j < i, x_2[j] \le x_1[i], y_2[j] \le y_1[i]}(\texttt{ans}[j] - x_2[j] - y_2[j])$
117117

118-
We notice that everything inside the $\min$ statement only depends on $j$. The segment tree stores $ans[j] - x_2[j] - y_2[j]$ at index $y_2[j]$. We can seperate the start and end of springboards to create two seperate events for each springboard, still sorting by $(x, y)$. When the event is the start of a springboard, update $ans[i]$ through a segment tree query. When the event is the end of a springboard, update the segment tree.
118+
We notice that everything inside the $\min$ statement only depends on $j$. The segment tree stores $\texttt{ans}[j] - x_2[j] - y_2[j]$ at index $y_2[j]$. We can seperate the start and end of springboards to create two seperate events for each springboard, still sorting by $(x, y)$. When the event is the start of a springboard, update $ans[i]$ through a segment tree query. When the event is the end of a springboard, update the segment tree.
119119

120120
By processing in order, the first two conditions in the $\min$ statement are always satisfied. The third is where the segment tree comes into play, where querying the range $[0, y_1[i]]$ is sufficent to satisfy all constraints.
121121

0 commit comments

Comments
 (0)