Library 3

시간 제한1초메모리 제한1024 MB

요약
주어진 배열을 올바른 배열로 되돌리는 데 필요한 교환 연산 횟수를 알려주는 오라클에 최대 5000번 질의해 숨겨진 올바른 배열을 알아낸다.
난이도

보통10점 중 7점

유형
수학, 구현, 완전 탐색, 정렬
정답자
아직 제출이 없습니다

문제

After several hundred years had passed, JOI city became a ruined city. IOI-chan, an explorer, is now exploring the area where the library was built. According to the results of exploration, the following are known:

  • There were a horizontal bookshelf in the library of JOI city. It had NN places in a line to put a book, numbered from 00 to N−1N - 1 from left to right. Exactly one book could be placed at each place.
  • There were NN books in the bookshelf. The NN books were numbered from 00 to N−1N - 1.
  • The arrangement of books is the way to place all the NN books at the NN places.
  • There was correct arrangement of the books, and the book B_iB\_i (0≤i≤N−10 ≤ i ≤ N - 1) was placed at place ii in the correct arrangement. Provided that B_iB\_i is all different.

It often happens that the arrangement of the books changes. We know that in this library, the books were put back in the correct arrangement by repeating the following operation.

operation Let book xx be the leftmost book among the books that the place of it differs from the place of the correct arrangement. Also let book yy be the book in the current arrangement at the place where book xx is placed in the correct arrangement. Swap the places of book xx and book yy.

Although IOI-chan found the old books of the library, she could not know the corrent arrangement. But she found an old machine which managed operations of the bookshelf of the library. If we specify the arrangement of the NN books and send a query to the machine, it answers the number of operations required to put back all the books in the correct arrangement. IOI-chan wants to know the correct arrangement of the books by sending queries to the machine. Because the machine is old, she can send at most 5,0005\\, 000 queries to the machine.

Write a program which, given infomation of the bookshelf, specify the correct arrangement of the books by sending at most 5,0005\\, 000 queries.

제한

  • 2≤N≤5002 ≤ N ≤ 500.
  • 0≤B_i≤N−10 ≤ B\_i ≤ N - 1 (0≤i≤N−10 ≤ i ≤ N - 1).
  • B_i≠B_jB\_i \ne B\_j (0≤i<j≤N−10 ≤ i < j ≤ N - 1).
  • Given values are all integers.

예제

이 문제는 공개된 예제가 없습니다.