E - Kite 解説
by
spheniscine
First sort the people primarily by ascending \(A_i\), but secondarily by descending \(B_i\), we’ll henceforth assume the list was presorted in this order.
Processing in this order, let the index of the current person be \(i\) . We want to find the maximum “chain” of people that could fly kites together whose \(B_j < B_i\), and add person \(i\) to that chain. Therefore, if we let \(\text{dp}\) be an associative array where \(\text{dp}[x]\) represents the maximum-length chain of people ending in \(B_j = x\), we could model the required update as:
\[\text{dp}[B_i] \xleftarrow{\max} \max(\{\text{dp}[x]: x < B_i\} \cup \{0\}) + 1\]
This would naively take \(O(N^2)\), but can be improved to \(O(N \log N)\) by first applying coordinate compression to all \(B_i\), then using a segment tree that handles range maximums and point updates.
Note the tricky case where \(A_i\) might be duplicated; this is why we sort secondarily by descending \(B_i\), so that duplicate \(A_i\) will never be part of the same chain.
投稿日時:
最終更新:
