Fill the Circle
Time limit2sMemory limit512 MB
Each number from 2 to N goes into the x-th empty slot clockwise from a reference number's slot on a circle, and the task is to print the circle starting at 1.
- Level
Medium7 of 10
- Topics
- Segment tree, Binary search, Array
- Solved
- No attempts yet
Problem
Sumin, who likes sequences, wants to build a sequence of the integers from to .
The sequence is built with the following rules.
- Place slots in a circle, and write in one slot in advance.
- For each number from to in order, repeat steps 3 and 4 to fill the slots.
- Choose one number already written and call it . Choose an integer between and , inclusive.
- Starting from the slot where is written and moving clockwise, find the -th empty slot you encounter, and write the number there.
- Starting from the slot where is written and moving clockwise, read the numbers in the slots in order. These form the sequence.
Input
The first line contains the size of the sequence, . ()
From the second line through line , line contains the reference integer and the number of steps . (, )
In other words, starting from the slot where is written and moving clockwise, number goes into the -th empty slot.
Output
Print lines. Line contains the -th number of the sequence.