CF467E.Alex and Complicated Task
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After you have read all the problems, probably, you think Alex is genius person. That's true! One day he came up with the following task.
Given a sequence of integer numbers _a_1, _a_2, ..., a__n. You are to find a longest sequence _b_1, _b_2, ..., b_4_m, that satisfies the following conditions:
- b_4_k + 1 = b_4_k + 3 for all valid integer k;
- b_4_k + 2 = b_4_k + 4 for all valid integer k;
- sequence b is subsequence of a (not necessarily contiguous subsequence).
And finally... Alex had given this complicated task to George, and George gave it to you. Help George to cope with the task.
在你读完所有题目后,你大概会觉得亚历克斯是个天才。的确如此!某天他提出了如下问题:
给定一个整数序列 a1,a2,…,an。你需要找出一个最长的序列 b1,b2,…,b4m,满足以下条件:
- 对所有合法的整数 k,有 b4k+1=b4k+3;
- 对所有合法的整数 k,有 b4k+2=b4k+4;
- 序列 b 是序列 a 的子序列(不一定是连续子序列)。
最后……亚历克斯把这个复杂的问题交给了乔治,而乔治又把它交给了你。请帮乔治解决这个问题。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 5·105). The next line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109).
第一行包含一个整数 n(1≤n≤5⋅105)。第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
输出格式
In the first line print a single integer 4_m_ — the maximal possible length of required sequence b. In the second line print 4_m_ integers _b_1, _b_2, ..., b_4_m, that is required sequence.
If there are multiple optimal answers you may print any of them.
第一行输出一个整数 4m —— 所需序列 b 的最大可能长度。
第二行输出 4m 个整数 b1, b2, …, b4m,即所要求的序列。
若存在多个最优解,可输出其中任意一个。
输入输出样例
输入#1
4 3 5 3 5
输出#1
4 3 5 3 5
输入#2
10 35 1 2 1 2 35 100 200 100 200
输出#2
8 1 2 1 2 100 200 100 200
输入解题思路,AI测评打分。不知道怎么写?