#P10436. [JOIST 2024] 卡牌收集 / Card Collection
[JOIST 2024] 卡牌收集 / Card Collection
Problem Description
JOI is passionate about collecting cards in a card game. Each card in the game has two integers representing its strength and cost. To obtain a new card, JOI brings cards to a card exchange. The cards are numbered from to . For the -th card (), its strength is and its cost is .
There are two machines available at the exchange. If you insert two cards and into one of the machines, you can obtain a card that satisfies the following:
- If you use the first machine, then the strength of is the maximum of the strengths of and , and the cost of is the maximum of the costs of and .
- If you use the second machine, then the strength of is the minimum of the strengths of and , and the cost of is the minimum of the costs of and .
JOI plans to use these machines exactly times to obtain one new card. To do this, he arranges the cards in order from card to card . Then, he repeats the following operation times:
- Choose two adjacent cards, use one of the machines to obtain a new card, and place the new card at the position of the two chosen cards before the operation.
After performing operations, JOI will have only one card left. The strength and cost of this card depend on the operations he performs.
JOI has a list of cards that he hopes to obtain after performing operations. The -th card () is represented by a pair of integers , where is its strength and is its cost. Write a program that, given information about JOI's cards and the list of cards he wants, determines which cards in the list he can obtain after performing operations.
Input Format
Read the following data from standard input.
- ...
- ...
Output Format
Write one line to standard output. The output should contain, in increasing order, the indices of all cards in the list that JOI can obtain after performing operations.
5 3
1 3
2 2
4 4
1 3
1 1
2 3
2 1
4 4
1 3
2 2
1 1
2 2
1 2
2 1
8 8
5 2
4 4
1 3
7 8
3 1
8 7
6 5
2 6
1 4
7 2
8 8
3 1
5 6
2 7
6 3
2 5
3 4 5 8
Hint
Sample Explanation 1
For example, JOI can obtain a card with strength 2 and cost 3 in the following way:
- Trade in card 4 and card 5 to obtain a card with strength 1 and cost 1.
- Trade in card 3 and the card obtained in the first operation to obtain a card with strength 1 and cost 1.
- Trade in card 1 and card 2 to obtain a card with strength 2 and cost 3.
- Trade in the cards obtained in the second and third operations to obtain a card with strength 2 and cost 3.
Note that even if a card with strength 2 and cost 3 is obtained in the third operation, JOI still needs to perform the last operation. Even if a certain card is obtained after some operations, it may still be impossible to obtain it after performing all operations.
The sample input satisfies the constraints of all subtasks.
Sample Explanation 2
As in this sample output, if it is impossible to obtain any card in the list after performing operations, output an empty line.
The sample input satisfies the constraints of all subtasks.
Sample Explanation 3
The sample input satisfies the constraints of all subtasks.
Constraints
- .
- .
- ().
- ().
- ().
- ().
- All given values are integers.
Subtasks
- (11 points) , .
- (38 points) , .
- (22 points) .
- (29 points) No additional constraints.
Translated by ChatGPT 5