#P8866. [NOIP2022] 喵了个喵

    ID: 7584 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2022NOIp 提高组Special JudgeO2优化

[NOIP2022] 喵了个喵

Description

Xiao E likes a game called "Meow Meow." The game has a deck and nn 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 mm cards whose patterns from top to bottom are a1,a2,,ama_1, a_2, \dots, a_m. There are kk types of patterns, numbered from 11 to kk. 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 TT 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 TT, the number of test cases.

Then for each of the TT test cases:

  • The first line contains three positive integers n,m,kn, m, k, denoting the number of stacks, the number of cards, and the number of pattern types on the cards.
  • The second line contains mm positive integers a1,a2,,ama_1, a_2, \dots, a_m, 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 op\mathrm{op}, the number of operations. You must ensure mop2×mm \leq \mathrm{op} \leq 2 \times m.

Then output op\mathrm{op} lines. Each line contains two or three positive integers separated by a single space.

  • If the line has two integers 1 s\texttt{1 s}, perform the first operation on stack ss.
  • If the line has three integers 2 s1 s2\texttt{2 s1 s2}, perform the second operation on stacks s1s_1 and s2s_2.

You must ensure 1s,s1,s2n1 \leq s, s_1, s_2 \leq n and s1s2s_1 \neq s_2.

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 meow/meow2.in\texttt{meow/meow2.in} and meow/meow2.ans\texttt{meow/meow2.ans} in the contestants' directory.

  • Constraints.

Let SS be the sum of mm over all TT test cases.

For all testdata, it is guaranteed that S2×106S \leq 2 \times 10^6, 1n3001 \leq n \leq 300, and 1aik1 \leq a_i \leq k.

::cute-table{tuack} | Test Point | T=T= | nn | k=k= | mm \leq | | :----------: | :----------: | :----------: | :----------: | :----------: | | 131\sim 3 | 10011001 | 300\leq 300 | 2n22n-2 | No limit | | 464\sim 6 | 10021002 | =2=2 | 2n12n-1 | ^ | | 7107\sim 10 | 33 | =3=3 | ^ | 1414 | | 111411\sim 14 | 10041004 | ^ | ^ | No limit | | 152015\sim 20 | 10051005 | 300\leq 300 | ^ | ^ | ::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 TT. Your output does not need to match the sample output; any valid solution earns points.

Translated by ChatGPT 5