Блог пользователя SriniV

Автор SriniV, история, 15 месяцев назад, По-английски

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!

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
15 месяцев назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

.