#P3850. [TJOI2007] 书架
[TJOI2007] 书架
Description
Mr. Knuth has a delicate bookshelf with books on it. He has bought different new books to learn more. He will insert the new books into the shelf one by one; he has already marked the position for each book and placed them accordingly. As Knuth is elderly, after a few days he can no longer remember which book is at certain positions. Can you help him?
Input Format
The first line contains the integer . The next lines are the titles of the books currently on the shelf in order (each title is a string without spaces, with length at most ).
The next line contains the integer . The following lines each contain the title of a book and the position where it should be inserted.
The next line contains the integer . Then there are queries; each line contains an integer denoting a position to query. (Positions on the shelf are numbered from .)
Output Format
Output lines. Each line contains the title of the book at the corresponding queried position.
3
Math
Algorithm
Program
2
Picture 2
System 1
3
0
1
3
Math
System
Picture
Hint
Originally there are three books: Math, Algorithm, Program. Later he buys two more books and inserts them at positions and . Each time a book is inserted, other books shift one position to the right. The final sequence on the shelf is:
0 Math
1 System
2 Algorithm
3 Picture
4 Program
The queries ask for positions , , , so the answers are: Math, System, Picture.
Constraints:
- For of the testdata, , , .
- For of the testdata, , , .
- For of the testdata, all constraints described in the statement hold: each insertion position never exceeds the current number of books on the shelf, and every queried position always has a book.
Translated by ChatGPT 5
京公网安备 11011102002149号