Calendar of Events
Time limit1sMemory limit128 MB
Given old and new schedules of N meetings, simulate prefix reversals that place each target day and list the request sizes.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Array, Sorting
- Solved
- No attempts yet
Problem
Marketing people are very creative and attend a great many meetings. The company's monthly schedule lists one meeting for each of the first days of the month. Every meeting is identified by a non-negative integer, and the same identifier may appear on several days.
The current schedule (the old order) must be turned into a chosen new order. The only operation the planning department may perform is a request: pick a number and reverse the meetings of the first days. For example, if the current order is 1 2 3 4 5, a request with turns it into 3 2 1 4 5.
Because an identifier may repeat, occurrences are matched by order: if a value is the -th occurrence from the left in the old order, that meeting must reach the position of the -th occurrence of the same value in the new order. This assigns to every day of the old schedule a unique target position in .
The department always follows this fixed procedure. For in this order:
- Let be the current position (counting from the front) of the day whose target position is ; this day is always among the first days.
- If , issue no request.
- Otherwise, if , first issue the request (reverse the first days); then issue the request (reverse the first days).
Report every request the procedure issues, in order.
Input
The input contains several reorganizations; the last one is followed by a line containing a single zero.
Each reorganization consists of three lines. The first line is an integer (), the number of days considered. The second line is the old schedule and the third line is the new schedule; each lists meeting identifiers (non-negative integers) separated by spaces. Both schedules contain the same multiset of identifiers, and some may appear more than once.
Output
For each reorganization, print one line with the request numbers issued by the procedure, separated by single spaces (). If the old and new schedules are already equal, the procedure issues no request; print an empty line.