Solution For 1859 — D : Andrey and Escape from Capygrad

Правка en2, от SriniV, 2023-08-18 15:27:53

Problem: 1859D - Andrey and Escape from Capygrad

As I went through the editorial ( video and text ), I saw that they were a bit complicated, and that there was an easier way ( with possibly the same idea ) to solve this problem.

Observation 1 ( as mentioned in both editorials ): It is never beneficial to teleport left. Therefore, each segment (l , r , a , b) can be re written and uniquely defined as (l , b , a , b).

Observation 2 ( also as mentioned in both editorials ): It is always optimal to teleport to b. Therefore, each segment can be re written as (l , b).

Final Observation: If any two segments (l , b) overlap, then we can travel between them ( combine them into one larger segment ).

Solution: Store all segments as (l , b) and combine them ( via sorting on left value ). Now when given a query, we just need to find whether it lies in any segment. If so, then we print the right end of that segment. Else we print the query itself! This can be done via binary search.

My Submission for reference : 219396665

Thanks!

Теги solution, div-2, 1859, div-2 d

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский SriniV 2023-08-18 15:27:53 3 Tiny change: 'blem:1859D\n\nAs I w' -> 'blem:1859D]\n\nAs I w'
en1 Английский SriniV 2023-08-18 15:27:37 1101 Initial revision (published)