아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Beads

시간 제한2초메모리 제한512 MB

요약
인접한 벨트 위의 구슬을 교환하는 스와퍼가 순서대로 작동할 때, 벨트 K에서 출발한 구슬이 J번째 스와퍼를 지난 뒤 어느 벨트에 있는지 답한다.
난이도

보통10점 중 6점

유형
시뮬레이션, 배열
정답자
아직 제출이 없습니다

문제

Professor X has recently revealed his latest invention to the world: the Ultimate Bead Swapper (UBS). As the name implies, it can make a sequence of beads much more interesting by swapping some beads in it!

The UBS has N conveyor belts placed in north-south direction in parallel. The conveyor belts are numbered 1 to N from left to right. Every belt moves from north to south at the same speed. There are M swappers placed between adjacent conveyors. No two swappers are equally far from the north end of the UBS. (In other words, they can be totally ordered according to how far they are from the north end.) The swappers are numbered 1 to M from north to south. Figure 1 shows the UBS when viewed from above.

Figure 1: An Ultimate Bead Swapper with 5 conveyor belts and 5 swappers.

To use the UBS, N beads are placed at the north end of the conveyor belts at the same time so that they form a horizontal row as they move along the belt. When two beads come under a swapper, the bead on the right conveyor belt is moved to the left conveyor belt, and the bead on the left conveyor belt is moved to the right conveyor. After being swapped, the two beads do not break the horizontal row. Figure 2 illustrates the behavior of a swapper.

Figure 2: (a) Four beads move along the conveyor belts. (b) Bead 2 and 3 trade places after going under the swapper.

Write a program that, given the number of conveyor belts N, the number of swappers M, and the positions of each swapper, answer questions of the form:

Given K and J, for the bead that is placed on Belt K at the north end of the UBS, which belt is the bead on after all beads just move past Swapper J?

입력

Your program should read from standard input. The first line contains the number of conveyor belts N(1 ≤ N ≤ 300, 000) and the number of swappers M(1 ≤ M ≤ 300, 000).

Swappers are listed from north to south in the following M lines. Each line contains one integer P(1 ≤ P ≤ M − 1), meaning that there is a swapper over conveyor belt P and P + 1.

예제1

  1. 예제 1

    입력
    5 5
    2
    4
    1
    3
    3
    
    예상 출력
    2
    3 4
    5 5