Choreography
Time limit8sMemory limit1024 MB
Determine a hidden permutation of 1 to 1000 using only queries that report whether the inversion count in a range is odd.
- Level
Medium7 of 10
- Topics
- Array, Math, Bit manipulation
- Solved
- No attempts yet
Choreography
Jura: Tvrtko, what was yesterday's performance like?
Tvrtko: It was great. The best part was when 1000 dancers lined up from left to right and started the choreography. Each of them had a number between and on their costume, and all the numbers were different. But I have to admit, when I watched them standing in line, I did not like their order.
Jura: What do you mean?
Tvrtko: I watched a contiguous range of dancers in the line and counted the pairs where the dancer in the earlier position had a bigger number than the dancer in the later position. I like it when that count is odd.
Jura: Oh Tvrtko, you have to see the whole picture. I will be the judge. So tell me, how were their numbers arranged in order?
Tvrtko: Hmm... I already forgot that. But I can tell you whether I liked each contiguous range of dancers or not.
Jura: I see. Then we have no choice but to try to determine their numbers from that.