#P2215. [HAOI2007] 上升序列
[HAOI2007] 上升序列
Description
Given a sequence , if there exists such that and , then is called an increasing subsequence of . If multiple satisfy the conditions, we want the lexicographically smallest one.
Task:
Given the sequence and several queries. For the -th query, find an increasing subsequence of length . If there are multiple, choose the lexicographically smallest one (i.e., first minimize ; if it is not unique, then minimize , and so on). If no increasing subsequence of length exists, print Impossible.
Input Format
- The first line contains an integer , the number of elements in the sequence.
- The second line contains integers: .
- The third line contains an integer , the number of queries. Each of the next lines contains one integer , asking for an increasing subsequence of length .
Output Format
For each query:
- If a valid subsequence exists, output the chosen subsequence’s elements on one line, separated by single spaces.
- Otherwise, print
Impossible.
6
3 4 1 2 3 6
3
6
4
5
Impossible
1 2 3 6
Impossible
6
6 7 1 2 3 4
1
2
6 7
Hint
Constraints: , . The testdata are random.
Translated by ChatGPT 5
京公网安备 11011102002149号