LCS3 - Long Common Subsequence

题意翻译

给你一个长度为$n$ 的序列$a$ ,$q$ 次询问一些长度为$m$ 的序列$b$ ,问$b$ 与$a$ 的最长公共子序列长度,并输出字典序最小的方案 $n\le10^6,q\le5\times10^3,m\le5,a_i,b_i\le10^4$ translated by @Kelin

题目描述

Given a sequence of N(1<=N<=1000000) numbers range from 0 to 10000 and several other sequence of M(0<=M<=5) numbers, you have to compute the Longest Common Subsequence of this sequences with the main sequence.

输入输出格式

输入格式


First line of the input will be N the number of elements of the main sequence. After that line there will be N numbers in one or more lines. Each of this number will be between 0 to 10000(inclusive). Then there will be Q(1<=Q<=5000) the number of query. Then following Q lines will be queries. In each query, start with a number M(0<=M<=5), followed by M numbers also between 0 to 10000(inclusive).

输出格式


For each query first print the number of elements in the longest common subsequence of the main and query sequences. Then print the subsequence. If there is more then one then print the lexicographically smallest.

输入输出样例

输入样例 #1

10
5 1 4 3 2 6 5 5 0 7
5
1 5
1 10
4 5 0 4 7
5 4 1 2 3 5
5 2 6 5 0 7
 

输出样例 #1

1 5
0
3 5 0 7
3 1 2 5
5 2 6 5 0 7