#P8866. [NOIP2022] 喵了个喵
[NOIP2022] 喵了个喵
Description
Xiao E likes a game called "Meow Meow." The game has a deck and stacks from which elements can be removed from the bottom. The task is to eliminate all cards according to the game rules. Initially, the deck contains cards whose patterns from top to bottom are . There are types of patterns, numbered from to . Each pattern appears an even number of times in the deck. All stacks are initially empty. The game allows two operations:
- Choose a stack and place the top card of the deck onto the top of that stack. After doing so, if the top two cards of this stack have the same pattern, they will be automatically removed.
- Choose two different stacks. If the cards at the bottoms of these two stacks have the same pattern, you may remove these two cards, and the cards that were originally just above the bottoms become the new bottoms. If the patterns are different, nothing happens.
There are levels in total. Xiao E cannot clear them. Please design a plan for each level: for every level, output an operation sequence that eliminates all the cards.
Input Format
The first line contains a positive integer , the number of test cases.
Then for each of the test cases:
- The first line contains three positive integers , denoting the number of stacks, the number of cards, and the number of pattern types on the cards.
- The second line contains positive integers , representing the patterns of the cards in the deck from top to bottom.
The testdata guarantees that there is a solution.
Output Format
For each test case, output several lines.
The first line contains a positive integer , the number of operations. You must ensure .
Then output lines. Each line contains two or three positive integers separated by a single space.
- If the line has two integers , perform the first operation on stack .
- If the line has three integers , perform the second operation on stacks and .
You must ensure and .
1
2 4 2
1 2 1 2
5
1 1
1 1
1 2
2 1 2
1 1
Hint
- Sample 1 Explanation.
The figure below shows the initial state.

The figure below shows the state after the first two operations.

The figure below shows the state after the third and fourth operations.

The figure below shows the state after the fifth operation.

- Sample 2.
See the files and in the contestants' directory.
- Constraints.
Let be the sum of over all test cases.
For all testdata, it is guaranteed that , , and .
::cute-table{tuack} | Test Point | | | | | | :----------: | :----------: | :----------: | :----------: | :----------: | | | | | | No limit | | | | | | ^ | | | | | ^ | | | | | ^ | ^ | No limit | | | | | ^ | ^ | ::cute-table{tuack}
- Scoring.
For each test case, your answer is considered correct if, after performing all operations in order, the deck is empty and all stacks are empty.
- Additional Hint.
You can determine which category a test point belongs to by the ones digit of . Your output does not need to match the sample output; any valid solution earns points.
Translated by ChatGPT 5
京公网安备 11011102002149号