#P3506. [POI2010] MOT-Monotonicity 2
[POI2010] MOT-Monotonicity 2
题目描述
This task is a harder version of task Monotonicity from the third stage of 17th Polish OI. It wasn't used in the contest itself.
For an integer sequence we define its monotonicity scheme as the sequence of symbols , or .
The symbol represents the relation between and .
For example, the monotonicity scheme of the sequence is .
We say that an integer sequence with monotonicity scheme , realizes another monotonicity scheme if for every it holds that .
In other words, the sequence can be obtained by repeating the sequence and removing appropriate suffix from that repetition.
For example, the sequence realizes each and every one of the following schemes:
as well as many others.
An integer sequence and a monotonicity scheme are given.
Your task is to find the longest subsequence () of the former that realizes the latter.
输入格式
The first line of the standard input holds two integers and (, ), separated by a single space, denoting the lengths of the sequences and monotonicity scheme respectively.
The second input line gives the sequence , i.e, it holds integers separated by single spaces ().
Finally, the third lines gives the monotonicity scheme , i.e., it holds s…
输出格式
In the first line of the standard output your program should print out a single integer , the maximum length of a subsequence of that realizes the scheme .
In the second line it should print out any such subsequence , separating its elements by single spaces.
题目大意
题目描述
本题是来自 POI 2010 第三阶段的单调性一题的加强版,但并没有在那次比赛中被使用。
译自 POI 2010 「Monotonicity 2」
对于一个整数序列 ,我们定义其“单调序列"为一个由 , 和 组成的符号序列 ,其中符号 表示 和 之间的关系。例如,数列 的单调序列为 。
对于整数序列 以及其单调序列 ,如果符号序列 满足对所有 有 ,我们就说序列 「实现」了序列 。也就是说,序列 可以通过重复多次 序列并删除一个后缀得到。例如,整数数列 至少实现了以下符号序列:
给定一个整数序列 以及一个单调序列 ,求出原整数序列最长的子序列 $a_{i_1}, a_{i_2}, ..., a_{i_m} (1 \le i_1 \lt i_2 \lt ... \lt i_m \le n)$ 使得前者的单调序列实现后者的符号序列。
输入格式
第一行包含用空格分隔的两个整数 ,分别表示整数序列 的长度和单调序列 的长度。
第二行包含用空格分隔的 个整数,表示序列 .
第三行包含用空格分隔的 个符号,表示符号序列 .
输出格式
第一行输出一个整数 ,表示序列 的最长的「实现」了单调序列 的子序列。
第二行输出任意一个这样的子序列 ,元素之间用空格分隔。
数据范围
对于 的数据, $1 \le n \le 500000,1 \le k \le 500000 , 1 \le a_i \le 1000000 , s_j \in \{<, >, =\}$ 。,>
7 3
2 4 3 1 3 5 3
< > =
6
2 4 3 3 5 3