#P3850. [TJOI2007] 书架

    ID: 2766 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2007各省省选平衡树枚举,暴力天津

[TJOI2007] 书架

Description

Mr. Knuth has a delicate bookshelf with NN books on it. He has bought MM 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 NN. The next NN lines are the titles of the NN books currently on the shelf in order (each title is a string without spaces, with length at most 1010).
The next line contains the integer MM. The following MM lines each contain the title of a book and the position where it should be inserted.
The next line contains the integer QQ. Then there are QQ queries; each line contains an integer denoting a position to query. (Positions on the shelf are numbered from 00.)

Output Format

Output QQ 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 22 and 11. 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 QQ queries ask for positions 00, 11, 33, so the answers are: Math, System, Picture.

Constraints:

  • For 30%30\% of the testdata, 1N1001 \leqslant N \leqslant 100, 1M1031 \leqslant M \leqslant 10^3, 1Q1031 \leqslant Q \leqslant 10^3.
  • For 100%100\% of the testdata, 1N2001 \leqslant N \leqslant 200, 1M1051 \leqslant M \leqslant 10^5, 1Q1041 \leqslant Q \leqslant 10^4.
  • For 100%100\% 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