Logo
(追記) (追記ここまで)

9871번 - The Bessie Shuffle 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB149673640.000%

문제

Bessie is practicing her card tricks. She has already mastered the Bessie- shuffle -- a shuffle on M (2 <= M <= 100,000) cards that reorganizes the cards so the i-th card from the top is now the P[i]-th card from the top.

Now Bessie is practicing shuffles on larger decks. She has a deck of N cards (M <= N <= 100,000) conveniently labeled 1 to N. She shuffles this deck by taking the first M cards and performing the Bessie-shuffle on them, placing the shuffled cards back on top of the deck. She then removes the top card from the deck and places it face down. She repeats this process, placing the top cards successively on top of each other, until she is out of cards. When Bessie has less than M cards left, she no longer performs the Bessie-shuffle, but continues to place the top card on top of the others.

Bessie knows that the deck initially started in sorted order, with 1 on top, 2 next, and N on the bottom. Given the description of the Bessie-shuffle, help Bessie compute which cards end up located at Q different specified positions (1 <= Q <= N, Q <= 5,000) in the deck.

입력

  • Line 1: A single line containing N, M and Q separated by a space.
  • Lines 2..1+M: Line i+1 indicates the position from the top, P[i], of the i-th card in the Bessie-shuffle (1 <= P[i] <= M).
  • Lines 2+M..1+M+Q: Line i+1+M contains a single integer q_i describing the i-th query. You are to compute the label on the card located in position q_i from the top (1 <= q_i <= N).

출력

  • Lines 1..Q: On the i-th line, print a single integer indicating the card at position q_i from the top.

제한

예제 입력 1

5 3 5
3
1
2
1
2
3
4
5

예제 출력 1

4
5
3
1
2

힌트

Input Details

Bessie has a deck of 5 cards initially ordered as [1, 2, 3, 4, 5]. Her shuffle is on 3 cards and has the effect of moving the top card to the bottom. There are 5 queries querying each position in the deck.

Output Details

The shuffle proceeds as:

  • [1, 2, 3, 4, 5] -> [2, 3, 1, 4, 5] (put 2 face down)
  • [3, 1, 4, 5] -> [1, 4, 3, 5] (put 1 face down)
  • [4, 3, 5] -> [3, 5, 4] (put 3 face down)
  • [5, 4] (put 5 face down)
  • [4] (put 4 face down)

This produces the final order of [4, 5, 3, 1, 2]

출처

Olympiad > USA Computing Olympiad > 2013-2014 Season > USACO December 2013 Contest > Silver 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /