Official

E - Dash Editorial by en_translator Editorial for printing


Basically, it is sufficient to simulate just as instructed in the problem statement. One issue is the spacial complexity. If you manage the positions of the items with a two-dimensional array, the spacial complexity becomes \(\mathrm{O}(X^2)\), where \(\mathrm{max}(|x_i|,|y_i|)=X\).

To improve this, it is enough to manage the items with a data structure like std::set. With this improvement, the problem can be solved with both the time and spacial complexity of \(\mathrm{O}(N + M\log M)\).

posted:
last update: