SriniV's blog

By SriniV, history, 16 months ago, In English

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!

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
16 months ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

.