virtual_contest_practice's blog

By virtual_contest_practice, history, 7 years ago, In English

I tried POI cards quite hard but failed to get the solution for 38% and 100% marks.Can anyone give a good hint to solve this question.Thanks in advance.

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Naive solution: After every swap, compute result from scratch. Computing from scratch is going from left to right and always picking smaller of two values that is at least number chosen from previous card or reporting error.

To sped this up use a simple segment tree that does that quicker. For every base interval you keep two informations. If you start with smaller number on first card, which card will be chosen from last card or report error, and analogous information if we start with greater number on first card. Such informations are easily mergeable and we can get complexity per query.