#P1820. 麻将 加强加强版

    ID: 11551 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2023图论建模有限状态自动机

麻将 加强加强版

Description

Xiao A found a strange set of Mahjong tiles: it only has number tiles 1,2,,n1,2,\cdots,n, and there are infinitely many copies of each tile.

A "pair" is two identical tiles (e.g., 2,22,2, 7,77,7). A "triplet" is three identical tiles (e.g., 1,1,11,1,1, 4,4,44,4,4). A "sequence" is three tiles with consecutive ranks (e.g., 1,2,31,2,3, 9,10,119,10,11; note that 11 and nn are not adjacent). "Sequence" and "triplet" are collectively called "melds."

If you can divide your hand into several "melds" (duplicates allowed) plus one "pair," then you can "complete the hand" (i.e., win).

If adding a certain tile to a hand allows it to "complete the hand," then the hand is said to be "waiting for" that tile.

Now Xiao A has randomly drawn kk tiles. He wants to know which tiles he is "waiting for."

Input Format

The first line contains two positive integers n,kn,k, representing the tile range and the number of tiles in Xiao A's hand.

The next line contains kk integers a1,a2,,aka_1,a_2,\cdots,a_k giving Xiao A's hand. Each number represents one tile in Xiao A's hand.

Output Format

Output several positive integers on the first line, indicating which tiles Xiao A is "waiting for." Please output them in ascending order.

If Xiao A is not "waiting for" any tile, output QAQ.

4 4
1 2 3 4
1 4
9 13
1 1 1 2 3 4 5 6 7 8 9 9 9
1 2 3 4 5 6 7 8 9
2 2
1 2
QAQ

Hint

  • Sample 1 explanation: two cases, 11/234 and 123/44.
  • Sample 2 explanation: this shape is the "pure Nine Gates" (纯正九莲宝灯), so it "waits for" every number tile.

Constraints

  • This problem uses bundled testdata.
  • Subtask 1 (10 pts): 1k161\leq k\leq 16.
  • Subtask 2 (10 pts): 1k4001\leq k\leq 400.
  • Subtask 3 (30 pts): 1k1031\leq k\leq 10^3.
  • Subtask 4 (30 pts): 1k3×1041\leq k\leq 3\times10^4.
  • Subtask 5 (20 pts): no special constraints.

For all testdata, 1aink2×1051\leq a_i\leq n\leq k\leq 2\times10^5.

Translated by ChatGPT 5